title: Laravel Passport, two tables for Login API
body: <p>I am trying to make a user authentication with two tables, a different table to 'users' and the one of 'users' which is the one with default Laravel, use Laravel passport. The detail is when I try to login with the second table I can not do the authentication because I do not recognize the users of the second table.</p>
  
  <p>-Model User2:  <code>-&gt;protected $guard_name='api2';</code></p>
  
  <p>-connection: <code>-&gt;protected $connection='mysql2';</code></p>
  
  <pre><code>**config/auth.php**
  
  'guards' =&gt; [
  'web' =&gt; [
      'driver' =&gt; 'session',
      'provider' =&gt; 'users',
  ],
  
  'api' =&gt; [
      'driver' =&gt; 'passport',
      'provider' =&gt; 'users',
  ],
  
  'api2' =&gt; [
      'driver' =&gt; 'passport',
      'provider' =&gt; 'users2',
    ], 
  ],
  
  'providers' =&gt; [
  
  'users' =&gt; [
      'driver' =&gt; 'eloquent',
      'model' =&gt; App\User::class,
  ],
  'user2' =&gt; [
      'driver' =&gt; 'eloquent',
      'model' =&gt; App\User2::class,
  ],
  ],
  </code></pre>
  
  <p><strong>My controller</strong></p>
  
  <pre><code>public function login(Request $request)
   {
  if (Auth::attempt($request-&gt;only('email', 'password'))) {
    $email = $request-&gt;only('email');
    $token =  $user-&gt;createToken('123456')-&gt;accessToken;
    $user-&gt;withAccessToken($token);
    $email=json_decode(json_encode($email));
    $user = User2::where('email', $email-&gt;email )-&gt;first()-&gt;only('id','name','email','employee_id');
  
    $user1 = User::find($user['id']);
  
    if(!$user1-&gt;hasAnyRole(Role::all())){
      return response()-&gt;json([
        'success' =&gt; false,
        'data' =&gt; '',
        'msg' =&gt; "does not have assigned role"
      ], 403);
    }
    $roles = $user1-&gt;getRoleNames()-&gt;first();
    $role = Role::findByName($roles,'api');
    $user=json_decode(json_encode($user));
  
    return response()-&gt;json([
      'success' =&gt; true,
      'token' =&gt; $token,
      'data' =&gt; [
        'user_id' =&gt; $user-&gt;id,
        'name' =&gt; $user-&gt;name,
        'email' =&gt; $user-&gt;email,
        'employee_id' =&gt; $user-&gt;employee_id,
        'role_id' =&gt; $role-&gt;id,
        'role_name' =&gt; $role-&gt;name
          ],
      'msg' =&gt; "Successfully"
    ], 200);
  } else {
    return response()-&gt;json(['error' =&gt; 'Unauthorised'], 401);
  }
  }
  </code></pre>