title: Laravel select user role and functions and list them up
body: <p>I want to ge the role per user and display them inside an table.</p>
  
  <p>What I want as output is something like this:</p>
  
  <p><img src="https://i.stack.imgur.com/T9frF.png" alt="output"></p>
  
  <p>So the table head <code>Functie</code> needs to be the function name of my database table column <code>name</code> inside table <code>roles</code>.</p>
  
  <p>My controller:</p>
  
  <pre><code>public function index()
      {
  
          $select_all_users = DB::table('users')-&gt;orderBy('username', 'DESC')-&gt;get();
  
          foreach ($select_all_users as $users) {
  
              //make an array object of the news
              $users = array();
  
              $select_user_role = DB::table('users')
              -&gt;join('roles', 'users.role_id', '=', 'roles.id')
              -&gt;select('roles.id', 'roles.name', 'roles.description', 'roles.color')
              -&gt;where('username', '=', Auth::user()-&gt;username)
              -&gt;first();
          }
  
  
  
          return View::make('admin.users.index')-&gt;with('select_user', $select_all_users);
      }
  </code></pre>
  
  <p>I know that the $select_user_role only will take the value of the users session...</p>
  
  <p>So now I want them listed per user.</p>
  
  <p>My view:</p>
  
  <pre><code>&lt;tbody&gt;
  
                              @foreach($select_user as $user)
  
                              &lt;td&gt;{{ ucfirst($user-&gt;username) }}&lt;/td&gt;
  
                              &lt;td&gt;{{ ucfirst($user-&gt;last_name) }}&lt;/td&gt;
  
                              &lt;td&gt;{{ $user-&gt;email }}&lt;/td&gt;
  
                              &lt;td&gt;Here needs to come the role name&lt;/td&gt;
  
                              &lt;td&gt;{{ $user-&gt;status }}&lt;/td&gt;
  
                              &lt;td&gt;{{ strftime('%A %d %B %Y', $user-&gt;registered_at) }}&lt;/td&gt;
  
                              &lt;td&gt;{{ strftime('%A %d %B %Y', $user-&gt;last_login) }}&lt;/td&gt;
  
                              &lt;td&gt;&lt;a href="{{ URL::to('admin/user/' . $user-&gt;id . '/edit') }}" class="btn btn-sm yellow"&gt;Bewerk &lt;i class="fa fa-edit"&gt;&lt;/i&gt;&lt;/a&gt;&lt;/td&gt;
  
                              &lt;td&gt;
                              {{ Form::open(['method' =&gt; 'delete',  'route' =&gt; ['admin.user.destroy', $user-&gt;id]]) }}
                                  {{ Form::button('Verwijderen &lt;i class="fa fa-user-times"&gt;&lt;/i&gt;', array('type' =&gt; 'submit', 'class' =&gt; 'btn btn-sm red')) }}
                              {{ Form::close() }}
  
                              &lt;/td&gt;
  
                              &lt;/tr&gt;
                              @endforeach
  
                              &lt;/tbody&gt;
  </code></pre>