title: How to use different guard when login in from web or api in Laravel?
body: <p>I am creating a Laravel (5.7) application for a mobile app. So I have an API and a Web Panel, both need to log in and each have a model. For Web login I use the <code>User</code> model (since this are operative roles) and another model <code>Client</code> for the users registered through the app.</p>
  
  <p>I am using <code>JWT</code> to create auth tokens for the mobile app and using the regular login for the Web Panel.</p>
  
  <p>The complication is that the default auth.php <code>guard</code> is <code>web</code> and if I use the (following) authenticate method from the API it goes to look to the users table, instead of the clients table, and its fixed when I change de default guard to api <strong>but the Web login then tries to look in the <code>clients</code> table</strong>.</p>
  
  <p>So, in short I've tried to switch this default guards in many different ways but it just won't work. Some of the tests (that failed) I did are:</p>
  
  <ul>
  <li>Changing the $guard variable in the login controller to web and setting api as default in auth.php</li>
  <li>Overwriting the defaults auth.php guard in execution time using <code>Config::set('auth.defaults.guard' , 'api');</code> or <code>config('auth.defaults.guard' , 'api');</code> (and all its variations) in my API's authenticate method</li>
  </ul>
  
  <p>This is my auth.php file</p>
  
  <pre><code>&lt;?php
  
  return [
  
      /*
      |--------------------------------------------------------------------------
      | Authentication Defaults
      |--------------------------------------------------------------------------
      |
      | This option controls the default authentication "guard" and password
      | reset options for your application. You may change these defaults
      | as required, but they're a perfect start for most applications.
      |
      */
  
      'defaults' =&gt; [
          'guard' =&gt; 'web',
          'passwords' =&gt; 'users',
      ],
  
      /*
      |--------------------------------------------------------------------------
      | Authentication Guards
      |--------------------------------------------------------------------------
      |
      | Next, you may define every authentication guard for your application.
      | Of course, a great default configuration has been defined for you
      | here which uses session storage and the Eloquent user provider.
      |
      | All authentication drivers have a user provider. This defines how the
      | users are actually retrieved out of your database or other storage
      | mechanisms used by this application to persist your user's data.
      |
      | Supported: "session", "token"
      |
      */
  
      'guards' =&gt; [
          'web' =&gt; [
              'driver' =&gt; 'session',
              'provider' =&gt; 'users',
          ],
  
          'api' =&gt; [
              'driver' =&gt; 'session',
              'provider' =&gt; 'clients'
          ],
      ],
  
      /*
      |--------------------------------------------------------------------------
      | User Providers
      |--------------------------------------------------------------------------
      |
      | All authentication drivers have a user provider. This defines how the
      | users are actually retrieved out of your database or other storage
      | mechanisms used by this application to persist your user's data.
      |
      | If you have multiple user tables or models you may configure multiple
      | sources which represent each model / table. These sources may then
      | be assigned to any extra authentication guards you have defined.
      |
      | Supported: "database", "eloquent"
      |
      */
  
      'providers' =&gt; [
          'users' =&gt; [
              'driver' =&gt; 'eloquent',
              'model' =&gt; App\User::class,
          ],
  
           'clients' =&gt; [
               'driver' =&gt; 'eloquent',
               'model' =&gt; App\Client::class,
           ],
      ],
  
      /*
      |--------------------------------------------------------------------------
      | Resetting Passwords
      |--------------------------------------------------------------------------
      |
      | You may specify multiple password reset configurations if you have more
      | than one user table or model in the application and you want to have
      | separate password reset settings based on the specific user types.
      |
      | The expire time is the number of minutes that the reset token should be
      | considered valid. This security feature keeps tokens short-lived so
      | they have less time to be guessed. You may change this as needed.
      |
      */
  
      'passwords' =&gt; [
          'users' =&gt; [
              'provider' =&gt; 'users',
              'table' =&gt; 'password_resets',
              'expire' =&gt; 60,
          ],
      ],
  
  ];
  </code></pre>
  
  <p>My authenticate method in my ApiClientController.php</p>
  
  <pre><code> public function authenticate(Request $request)
      {
  //        config('auth.defaults.guard' , 'api'); // NOT WORKING!!
  //        Config::set('auth.guards.web.provider', 'clients'); // NOT WORKING!!
  //        Config::set('auth.providers.users.model', Client::class); // NOT WORKING!!
  //        config('auth.providers.users.model', Client::class); // NOT WORKING!!
  
          $credentials = $request-&gt;only('phone', 'password');
  
          try {
              if (! $token = JWTAuth::attempt($credentials)) {
                  return response()-&gt;json(['error' =&gt; 'invalid_credentials'], 400);
              }
          } catch (JWTException $e) {
              return response()-&gt;json(['error' =&gt; 'could_not_create_token'], 500);
          }
  
          Log::info("JWT Token: $token");
  
          return response()-&gt;json(compact('token'));
      }
  </code></pre>
  
  <p>Also, here is my Client model</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  
  use Tymon\JWTAuth\Contracts\JWTSubject;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  
  class Client extends Authenticatable implements JWTSubject
  {
  
      protected $hidden = [
          'password', 'phone_verification_code', 'phone_verified_at'
      ];
  
      public function getJWTIdentifier()
      {
          return $this-&gt;getKey();
      }
      public function getJWTCustomClaims()
      {
          return [];
      }
  
  }
  </code></pre>