Read through this post it has examples of getting data from Json.
https://laracasts.com/discuss/channels/javascript/how-to-read-value-of-javascript-object
And just FYI looping over Json has been covered many times on this forum.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello!
I'm only just learning Laravel and I'm trying to use it in the simplest way: get data (JSON) from an HTTP endpoint and loop through it in a Blade template.
{
"records": [
{
"id": "recCC9bmU",
"createdTime": "2022-11-30T20:51:57.000Z",
"fields": {
"Revision Number": "P1",
"Project Number": "0190",
"Cut Ticket BOM": [
"recVH4co7U",
"recR0AogvB"
],
"Color Code": "OO",
"Description": "description",
"Size": "LG"
}
},
{
"id": "recPzRfs7",
"createdTime": "2022-12-05T18:06:18.000Z",
"fields": {
"Project Number": "0190",
"Revision Number": "P1",
"Qty.": 32
}
}
]
}
I want to loop over records in my Blade template.
I've looked at the documentation and I've read through several search results. I've tried at least 30 variations of the code below but nothing is working and so now I'm thoroughly lost. I thought I had found "the answer" several times but always end up with an error of some kind:
Route::get('/cut-ticket', function () {
// forum system is forcing me to obscure the URL; rest assured it works
$cutTicketUrl = '...url...';
$response = Http::withToken('keypb')->acceptJson()->get($cutTicketUrl);
$data = $response->json();
return view('cut-ticket', ['data' => $data->records]);
});
This results in Attempt to read property "records" on array.
I don't understand what that error message is trying to say. $data itself is not an array, it's an object. records is the array. Why is records not available from $data?
@jlrdw I ended up finding a post on Stackoverflow that lead me to the answer indirectly. It turns out my major problem was the wrong syntax. I have been writing $data->records when I should have doing $data['records'].
One thing you have to keep in my when helping people is that things which are obvious to you are not always obvious to someone else. It can be hard to see from the "newbie's" perspective.
edit: Forgot to mention that I am not using JavaScript. My view currently looks like:
@foreach ($data as $datum)
{{ $datum['id'] }}<br/>
@endforeach
Please or to participate in this conversation.