简体   繁体   English

如何管理 laravel sanctum 包上的多个连接?

[英]How to manage multiple connection on laravel sanctum package?

We are working on project where multiple databases are connected.我们正在研究连接多个数据库的项目。 We have created connections ie dbconnection1 and api .我们已经创建了连接,即dbconnection1api We are facing problem in connecting sanctum auth to different connection ie api after upgrading Laravel to 9.在将 Laravel 升级到 9 后,我们在将 sanctum auth 连接到不同的连接(即api )时遇到了问题。

Earlier it was working perfectly, after upgrading Laravel version, we could not connect to different connection.之前它运行良好,升级 Laravel 版本后,我们无法连接到不同的连接。

We have mentioned connection in respective Modal ie protected $connection = 'api';.我们在各自的 Modal 中提到了连接,即受保护的 $connection = 'api';。

But still sanctum is not connecting to correct database.但仍然 sanctum 没有连接到正确的数据库。 Currently we have extended PersonalAccessToken Model as per sanctum documentation and added protected $connection = 'api';目前,我们根据 sanctum 文档扩展了 PersonalAccessToken 模型,并添加了 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.由于我们不认为只提及连接,我们应该扩展 PersonalAccessToken 模型。

You are correct, since PersonalAccessToken extends Model, which by default uses the default connection, you need to specify different connection like other models.您是对的,因为 PersonalAccessToken 扩展了 Model,默认情况下使用默认连接,您需要像其他模型一样指定不同的连接。 Otherwise you can set 'api' as the default connection否则,您可以将“api”设置为默认连接

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM