I am working in laravel project and i want to display my json data from url into the view dashboard.blade, And this is the sample json data:
{"response":{"result":{"Contacts":{"row":[{"no":"1","fl":[{"val":"CONTACTID","content":"144120000000079041"},{"val":"First Name","content":"Tata"},{"val":"Last Name","content":"Nyerere"},{"val":"Email","content":"[email protected]"},{"val":"Account Name","content":"null"},{"val":"Phone","content":"255652400670"},{"val":"Mobile","content":"null"}]},{"no":"2","fl":[{"val":"CONTACTID","content":"144120000000069001"},{"val":"First Name","content":"Daniel"},{"val":"Last Name","content":"Nyerere"},{"val":"Email","content":"[email protected]"},{"val":"Account Name","content":"null"},{"val":"Phone","content":"255754897505"},{"val":"Mobile","content":"null"}]},{"no":"3","fl":[{"val":"CONTACTID","content":"144120000000065068"},{"val":"First Name","content":"Lawrence"},{"val":"Last Name","content":"Zoho"},{"val":"Email","content":"[email protected]"},{"val":"ACCOUNTID","content":"144120000000065066"},{"val":"Account Name","content":"Zoho"},{"val":"Phone","content":"1 888 900 9646"},{"val":"Mobile","content":"null"}]}]}},"uri":"/api/json/contacts/getrecords"}}
And here is my Controller method:
public function getDashboard()
{
$url = "MY URL IS HERE";
$json = file_get_contents($url);
$json = json_decode($json, true);
$response = $json['response'];
$result = $response['result'];
$contact = $result['Contacts'];
$data = $contact['row'];
return view('dashboard')->with('posts', $data);
}
And here is my dashboard.blade that displays the json data on my view page:
@foreach($posts as $post)
@foreach($post['fl'] as $row)
<article class="post">
@if($row['val'] == 'First Name')
First Name: {{ $row['content'] }}
@endif
</article>
@endforeach
@endforeach
Can anyone assist me on the issue and how to write the foreach in dashboard.blade file as i want to display the data on my view as:
First Name Last Name Phone:
Tata Nyerere 255754897505
As for now it only display
First Name: Tata
Please assist me as i have spent time to solve this I will appreciate your help guys. Thanks in advance`
