#Hi! Laravel starter here. I would like to show API response on main laravel screen

6 messages · Page 1 of 1 (latest)

pastel rock
icy grove
pastel rock
# icy grove I guess start by reading through the docs on making an API request; <https://lar...

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

icy grove
#

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

pastel rock
icy grove