I am trying to display data from external API using Http
web.php:
Route::resource('job', 'App\Http\Controllers\AjaxController');
Controller:
public function index()
{
$apis = Http::get("example/api/records");
return view("job.index", [
"apis" => json_decode($apis)
]);
}
view:
@foreach ($apis as $item)
<h1>{{$item->DocKey}}</h1>
@endforeach
I am getting the data from the api inside the view as showing below:
but i get this error:
Undefined property: stdClass::$DocKey
what seems to be the problem here?
CodePudding user response:
Your controller should look like:
$response = Http::get('http://yourdomain.com/example/api/records');
$apis = json_decode($response->body());