title: Can Laravel Auth::attempt() handle relationships?
body: <p>I'm using <a href="https://github.com/Zizaco/entrust" rel="nofollow noreferrer">entrust</a> for managing role based permissions in Laravel 5.3, and naturally using manual/custom logins for different user types. Is it possible for <code>Auth::attempt()</code> to handle foreign table relationships? Basically, I want to do something like this: </p>
  
  <pre><code>if(Auth::attempt(['email' =&gt; $request-&gt;email, 'password' =&gt; $request-&gt;password, hasRole('teacher') =&gt; true])) {
          return redirect()-&gt;intended('teacher/dashboard');
  }
  </code></pre>
  
  <p>But I keep getting the error that <code>hasRole()</code> is an undefined function. I have included <code>use Zizaco\Entrust\Traits\EntrustUserTrait;</code> and <code>use EntrustUserTrait;</code>, which I thought would provide me with access to the function, but apparently not. </p>
  
  <p>I appreciate the fact that <code>hasRole()</code> is a method for user objects, and at the time of checking I don't have a user object but I can't do a role check after attempt has succeeded because then the user has already been logged in, and if the role was wrong I would need to log them out as their credentials are correct, but not for the role; which seems slow and not pragmatic. </p>
  
  <p>How should I go about handling this? Is there an alternative to <code>Auth::attempt</code> that I can use that will not log in the user, but check the user exists with specified input, and then run the role check, and then use another function to start an authenticated session?</p>
  
  <p>If useful my LoginController is here:</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers\Teacher;
  
  use App\Http\Controllers\Controller;
  use Illuminate\Support\Facades\Auth;
  use Illuminate\Http\Request;
  use Validator;
  use Zizaco\Entrust\Traits\EntrustUserTrait;
  
  class LoginController extends Controller {
      use EntrustUserTrait;
  
      public function showLoginForm() {
          return view('teacher/login');
      }
  
      public function authenticate(Request $request) {
          Validator::make($request-&gt;all(), [
              'email' =&gt; 'required|email',
              'password' =&gt; 'required',
          ])-&gt;validate();
  
          if(Auth::attempt(['email' =&gt; $request-&gt;email, 'password' =&gt; $request-&gt;password, hasRole('teacher') =&gt; true])) {
              return redirect()-&gt;intended('teacher/dashboard');
          }
  
          return redirect('admin/login')-&gt;with('invalid', 'Invalid username or password');
      }
  }
  </code></pre>
  
  <p>Any help or direction would be much appreciated. Thanks.</p>