Home > other >  Retrieve data from external API and pass multiple data to my view
Retrieve data from external API and pass multiple data to my view

Time:03-01

In my controller i have this function

public function GetStatusDetails()

{
    $response = Http::get('https://exemple.exemple.com/fr/api/<token>/availability/<Id>/getStatusDetails?format=json');
    $StatusDetails = json_decode($response->body(), true);
    //dd($data);
    return view('ControlmAPI.netvigie', [
        'StatusDetails' => $StatusDetails
    ]);

}

public function GetStatus()

{
    $response = Http::get('https://exemple.exemple.com/fr/api/<token>/availability/<Id>/getStatus?format=json');
    $Status = json_decode($response->body(), true);
    //dd($data);
    return view('ControlmAPI.netvigie', [
        'Status' => $Status
    ]);

}

Is not the same call api but when i want to use StatusDetails in my blade i can't but Status i can so my question is how to pass multiple data to my blade and use it separately.

the dd of them is DD so in my blade i do {{$Status[0]['status']}} it work but when i want to do for "StatusDetails" it doesn't but if i do only for "StatusDetails" it works but not for both someone have the solution please ?

CodePudding user response:

You can simply pass them as an array

public function GetStatus()

{
    $statusResponse = Http::get('https://exemple.exemple.com/fr/api/<token>/availability/<Id>/getStatus?format=json');
    $statusDetailsResponse = Http::get('https://exemple.exemple.com/fr/api/<token>/availability/<Id>/getStatusDetails?format=json');
    $Status = json_decode($statusResponse->body(), true);
    $StatusDetails = json_decode($statusDetailsResponse->body(), true);

    return view('ControlmAPI.netvigie', [
        'Status' => $Status,
        'StatusDetails' => $StatusDetails,
    ]);
}
  • Related