title: How to access laravel collection in a foreach loop in blade template?
body: <p>I want to get the user name details from the table <code>Users</code> with the author <code>id</code>s from the table <code>Pages</code>. For this, I have made a <code>foreach</code> loop and added the data to <code>users</code> array.</p>
  
  <p>This gets the data but its not properly formatted to use in blade template. Below is the code :</p>
  
  <pre><code>$pages = \App\page::all();
      $users = array();
      foreach ($pages as $page) {
          $user = \App\user::where('id', $page-&gt;author)-&gt;get('name');
          $users[] = $user;
      }       
      dd($users);
      return view('admin.pages', compact('pages', 'users'));
  </code></pre>
  
  <p>I have dumped the results with <code>dd($users)</code> method and got this:
  <img src="https://i.imgur.com/i5gT6Ab.png" alt="Image"></p>
  
  <p>I am using this code in the blade template to retrieve but getting blank white space at the <code>$users[$loop-&gt;index]-&gt;get('name')</code> place.</p>
  
  <pre><code>@foreach ($pages as $page)
              &lt;tr&gt;
                &lt;th&gt;{{ $page-&gt;id }}&lt;/th&gt;
                &lt;th&gt;{{ $page-&gt;title }}&lt;/th&gt;
                &lt;th&gt;{{ $users[$loop-&gt;index]-&gt;get('name') }}&lt;/th&gt;
                @if($page-&gt;status = 'ACTIVE')
                &lt;th&gt;&lt;span class="label label-success"&gt;{{ $page-&gt;status }} &lt;/span&gt;&lt;/th&gt;
                @elseif($page-&gt;status = 'DRAFT')
                &lt;th&gt;&lt;span class="label label-warning"&gt;{{ $page-&gt;status }} &lt;/span&gt;&lt;/th&gt;
                @endif
                &lt;th&gt;{{ $page-&gt;Actions }}&lt;/th&gt;
              &lt;/tr&gt;
              @endforeach
  </code></pre>