How to manage multiple connection on laravel sanctum package?

605 Views Asked by At

We are working on project where multiple databases are connected. We have created connections i.e. dbconnection1 and api. We are facing problem in connecting sanctum auth to different connection i.e. api after upgrading Laravel to 9.

Earlier it was working perfectly, after upgrading Laravel version, we could not connect to different connection.

We have mentioned connection in respective Modal i.e. protected $connection = 'api';.

But still sanctum is not connecting to correct database. Currently we have extended PersonalAccessToken Model as per sanctum documentation and added protected $connection = 'api'; line there.

But we would like to know if there is any better option for this? As We don't think just to mention connection we should extend PersonalAccessToken Model.

1

There are 1 best solutions below

1
On BEST ANSWER

You are correct, since PersonalAccessToken extends Model, which by default uses the default connection, you need to specify different connection like other models. Otherwise you can set 'api' as the default connection