Certainly! The issue is that you are encoding your data to JSON in the controller, so when you loop in the Blade template, each $value is a JSON string, not an array/object. To access individual fields (like name, bank_orders, itens), you need to decode the JSON string back to an array/object in your Blade template.
Solution:
1. Controller (Recommended: Don't Encode to JSON)
Instead of encoding to JSON in your controller, just pass the array to the view:
// Controller
// $result is already an array of arrays/objects
return view('your-view', ['structure' => $result]);
2. Blade Template
Now, you can loop through the array directly and access its properties:
@foreach($structure as $item)
<table>
<tr>
<td>Name:</td>
<td>{{ $item['name'] }}</td>
</tr>
<tr>
<td>Number:</td>
<td>{{ $item['number'] }}</td>
</tr>
<tr>
<td>Bank Orders:</td>
<td>
<ul>
@foreach($item['bank_orders'] as $order)
<li>
Operation Number: {{ $order['operation_number'] }}<br>
Category: {{ $order['category_invest']['category'] }}<br>
Items:
<ul>
@foreach($order['itens'] as $it)
<li>
Item Number: {{ $it['item_number'] }}<br>
Contract Data: {{ $it['contract_data'] }}<br>
Payment Date: {{ $it['payment_date'] }}<br>
Amount Payment: {{ $it['amount_payment'] }}
</li>
@endforeach
</ul>
</li>
@endforeach
</ul>
</td>
</tr>
</table>
@endforeach
3. If You Must Use JSON (Not Recommended)
If you must keep the JSON encoding, decode it in the Blade template:
@foreach($structure as $jsonValue)
@php
$item = json_decode($jsonValue, true);
@endphp
<table>
<tr>
<td>Name:</td>
<td>{{ $item['name'] }}</td>
</tr>
<!-- Repeat as above -->
</table>
@endforeach
Summary:
- Best practice: Pass arrays/objects to the view, not JSON strings.
- If you have JSON: Use
json_decode($value, true)in Blade to convert it back to an array.
Let me know if you need help with a specific part of the structure!