Blade foreach cast output to an object
<p>I am trying to figure out how I can give my data output in the blade file, the Laravel look;</p>

<blockquote>
  <p>like <code>$data-&gt;name</code></p>
</blockquote>

<p>But I can't get the output to be casted as an object. I think I have to make an array of the data before I can loop it proper in a <code>foreach</code> but this doesn't feel like the right way.</p>

<p>I am relatively new to Laravel and I want to do this the nice way, can someone point me in the right direction? Thanks in advance</p>

<p>Controller:</p>

<pre><code>$data = collect($this-&gt;api-&gt;organization-&gt;index())-&gt;toArray();

return View::make('pages.organization.index', array('data' =&gt; $data[0]));
</code></pre>

<p>View:</p>

<pre><code>@foreach($data as ((object)$organization))
    {{ $organization-&gt;name }}
@endforeach
</code></pre>

<p>I know this will not work, but I  think it illustrates my question a little bit.</p>

<p><strong>EDIT</strong></p>

<p>What I didn't realize is that <code>$data = collect($this-&gt;api-&gt;organization-&gt;index());</code> is returning an array with all the data arrays inside because I didn't name it in my return like this:</p>

<pre><code>return (object)['all' =&gt; $data];
</code></pre>

<p>After adding <code>all</code> I could reference the code inside my view like I wanted to. I know this is not a very detailed answer, if you run into the same problem message me I'll edit the answer.</p>