This post helped me to figure out how to use Passport for my API, while having different databases for subdomain accounts. In my application, each valid subdomain has its own database with a users table.
I have two User models: DefaultUser and AccountUser which extend App\User.
My App\User model has the changeConnection function and I call that function in a CustomUserProvider class, which is used by a CustomAuthProvider class, and in my config/auth.php I have:
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'default_api' => [
'driver' => 'passport',
'provider' => 'default_users',
],
'account_api' => [
'driver' => 'passport',
'provider' => 'account_users',
],
],
...
'providers' => [
'default_users' => [
'driver' => 'custom',
'model' => App\Models\DefaultUser::class,
],
'account_users' => [
'driver' => 'custom',
'model' => App\Models\AccountUser::class,
],
'users' => [
'driver' => 'custom',
'model' => App\User::class,
],
It appears to be working for me so far, so I am moving on. Hopefully this helps anyone who gets here as I did.