mercredi 17 janvier 2018

Issue with returning a foreach loop in Laravel controller to blade view

I am trying to do a foreach loop in a curL request in a method of a controller.

public function getDataFromApi()
{

    $cong = Stream::pluck('name');

    foreach($cong as $gemeente)
    {
        $client = new Client([
            'headers'  => [
                'content-type' => 'application/json',
                'Accept' => 'application/json',
            ],
        ]);

        $response = $client->request('GET', 'http://xx.xx.xx.xx:xxxx/v2/servers/_defaultServer_/vhosts/_defaultVHost_/applications/'.$gemeente.'/instances/_definst_');

        $data = $response->getBody();
        $data = json_decode($data);
        $data = $data->incomingStreams;
    }

    return view('streams.api', compact('data'));
}

But when I try to output the result in a blade view page doing a diedump it returns an empty array [] while I know for certain it should return at least ONE result of an active stream.

What am I doing wrong?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2DeiVjd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire