#Hi! Laravel starter here. I would like to show API response on main laravel screen
6 messages · Page 1 of 1 (latest)
I guess start by reading through the docs on making an API request; https://laravel.com/docs/10.x/http-client
Hi, I've created new controller with the code:
`<?php
namespace App\Http\Controllers;
use Illuminate\Support\Facades\Http;
class PageController extends Controller
{
public function supername(){
$response = Http::get('http://ip-api.com/json/')['supername'];
$supername = Http::get('http://ip-api.com/json/')['supername'];
}
}`
but when I call "supername" in the welcome.blade.php it drop me the error Undefined variable $supername
Well first off, you're not rendering any view in that controller https://laravel.com/docs/10.x/views
Secondly, that response doesn't return a supername key, so it would be null either way?
You might want to consider learning some of the basics of Laravel (and PHP), Laracasts has a few series on Laravel and PHP. There's also the https://bootcamp.laravel.com to get an idea how Laravel works
I just need to get that working and nothing else. I do not want to learn Laravel futurwise
I'm giving you the direction you should look for to solve it tho? We're not here to build an app for you, if you want someone else to build your app you could just hire someone to do it for you.