Ad

I Got The Json Data From The Url And I Need To Print The Json Data In My Laravel 5.6 View

Trying to print the json data in my laravel5.6 view using controller. I got an error

Illegal string offset 'rates'

My Controller Code

 $req_url = 'https://v3.exchangerate-api.com/bulk/6eea6e74c3abe1df9de390c2/USD';
 $response_json = file_get_contents($req_url);
 $configdata4   = json_encode($response_json);
 $final_data4 = json_decode($configdata4,true);
 return view('clientlayout.main.registerdomain',compact('final_data4'));

My view page Code

@foreach($final_data4['rates'] as $value)
{{$value['USD']}}
@endforeach

Please suggest any solutions to this issue.

Ad

Answer

Your already get the response in json format, all you need to do is to decode and return it, as the following:

$req_url = 'https://v3.exchangerate-api.com/bulk/6eea6e74c3abe1df9de390c2/USD';
$response_json = file_get_contents($req_url);
$final_data4 = json_decode($response_json);
return view('clientlayout.main.registerdomain',compact('final_data4'));
Ad
source: stackoverflow.com
Ad