I am trying to iterate through the values of a JSON ARRAY with no success. When the file has a single value, I loop through it with no problem.
Controller
$data = '[{
"T": {
"HD": {
"HD01": "1",
"HD02": "06033942",
"HD03": "3736803"
}
}
}]';
$data = json_decode($data);
return view('dashboard.book.index', ['data' => $data[0]]);
Blade
<tbody>
@foreach($data as $item)
<tr>
@foreach($item->HD as $title)
<td>{{ $title }}</td>
@endforeach
</tr>
@endforeach
<tbody>
Result
But when it starts to have more than one value, I can't get the same results:
Controller
$data = '[{
"T": {
"HD": {
"HD01": "1",
"HD02": "06033942",
"HD03": "3736803"
}
}
},
{
"T": {
"HD": {
"HD01": "2",
"HD02": "06035419",
"HD03": "4736521"
}
}
}]';
$data = json_decode($data);
return view('dashboard.book.index', ['data' => $data]);
Result
With $data[0] I get the values individually, but when I want to send the whole array I get errors.
How can I modify my code to make it work?