title: Authenticating a user role in Laravel and protecting a route
body: <p>I have taken advice from people here and given Laravel a try, I have been trying to create a user authentication system.  I am having trouble translating what I know works in PHP to Laravel using Eloquent.</p>
  
  <p>What I am trying to do here is identify a user, their roles, if the user has a role of admin they can access the route /admin</p>
  
  <p>I know I can use a package such as Entrust but that is not really helping me learn.</p>
  
  <p>I have created Models for both User and Role.  I also have a lookup table called role_user with a user_id and role_id.</p>
  
  <p>In <strong>User.php</strong> I have </p>
  
  <pre><code>public function roles(){
  
      return $this-&gt;belongsToMany('Role', 'users_roles');
  
  }
  </code></pre>
  
  <p>In <strong>Role.php</strong> I have</p>
  
  <pre><code>public function users()
  {
      return $this-&gt;belongsToMany('User', 'users_roles');
  }
  </code></pre>
  
  <p>I know if I used</p>
  
  <pre><code>$roles = user::find(1)-&gt;roles;
  return ($roles);
  </code></pre>
  
  <p>It will and does return the correct user id (1) and the roles assigned to that user.  Now what I am struggling with is how to pick out the admin role and only if the user has this will it allow access to /admin</p>
  
  <p>The route should essentially be </p>
  
  <pre><code>Route::get('admin', function()
  {
  
      return View::make('admin.index');
  
   })-&gt;before('auth');
  </code></pre>
  
  <p>What I can't figure how/where/should I check for the admin role first and how to then apply that to the auth check to only permit an admin access to the route.</p>
  
  <p>Any help appreciated.</p>
  
  <p>Lee</p>