Home > database >  How to get currencies from rest coutries API v3.1 using Laravel?
How to get currencies from rest coutries API v3.1 using Laravel?

Time:01-06

enter image description here

enter image description here

@foreach ($responseBody as $response)
<div >
    <div >Official Name</div>
    <div >{{$response->name->official}}</div>
</div>
<div >
   <div >Currencies</div>
   <div >{{ $response->currencies???? }}</div>
</div>
@endforeach

I using Laravel to consume API from https://restcountries.com/. I success to get Name of the country, but I still failed to get the currencies. The "SGD" code is different for each country. How to get the name of currencies?

CodePudding user response:

You should run another loop for the currencies:

@foreach($response->currencies as $id => $info)
    <b>{{ $id }}</b>: {{ $info->name }} {{ $info->symbol }}
@endforeach
  • Related