I’m getting json data but I can’t list it in datatable
Controller File
JavaScript
x
public function index()
{
$data = Http::get('https://jsonplaceholder.typicode.com/posts');
return view('frontend.default.index', ['data'=> $data->json()]);
}
View File
JavaScript
<table id="table_id" class="display">
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
</tr>
</thead>
<tbody>
@foreach ($data as $key => $value)
<tr>
<td>
{{$value->title}} // not working
</td>
<td>Row 1 Data 2</td>
</tr>
@endforeach
</tbody>
</table>
Advertisement
Answer
The data you pull from json comes as an array. You are trying to print as an object while you print.
Solution
JavaScript
@foreach ($data as $key => $value)
<tr>
<td>
{{$value['title']}} // not working
</td>
<td>Row 1 Data 2</td>
</tr>
@endforeach