Problem with returning a foreach loop from Laravel controller to blade view

Posted 10 months ago by Edelco

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

method (from StreamsController):

 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'));

My blade page:


{{ dd($data) }}
@foreach($data as $result)
    <h3>{{ $result->name }}</h3>


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?

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.