title: Concept of laravel first() method
body: <p>The laravel <code>first()</code> method is pretty straight forward and that's why this question might be silly, but I am not understanding the use of <code>first()</code> method.</p>
  
  <p>Actually, I'm following a youtube tutorial where I am authenticating a user if he has the role of <code>admin</code> then only he will get the access of <code>route</code> otherwise will be redirected to <code>home</code>.</p>
  
  <p>There is no error or issue with code but my understanding.</p>
  
  <p>I am returning the user in <code>User</code> model class function if the user has the role passed by the middleware</p>
  
  <p>Route</p>
  
  <pre class="lang-php prettyprint-override"><code>Route::get('admin', function (){
       return 'This is Admin page';
  })-&gt;middleware(['auth', 'auth.admin']);
  </code></pre>
  
  <p>Middleware</p>
  
  <pre class="lang-php prettyprint-override"><code>public function handle($request, Closure $next)
  {
      if (Auth::user()-&gt;hasAnyRole('admin'))
      {
          return $next($request);
      }
      return redirect('home');
  }
  </code></pre>
  
  <p>User Modal</p>
  
  <pre class="lang-php prettyprint-override"><code>public function hasAnyRole($role)
  {
      return null !== $this-&gt;roles()-&gt;where('name', $role)-&gt;first();
  }
  </code></pre>
  
  <p>If I use <code>first()</code> method in <code>hasAnyRole</code> function then only <code>route</code> is protected by other users and only <code>admin</code> get access to the route,
  If I remove the <code>first()</code> method then all the users get access to <code>route</code> which I don't understand why?</p>