[英]How to assign Spatie\Permission\Traits\HasRoles and Authenticatable to different models with Laravel
There are 2 models:有2种型号:
User & Account用户帐号
Each user has several accounts with different roles (one-to-many relation).每个用户都有多个具有不同角色的帐户(一对多关系)。
The User is Authenticatable用户是可验证的
User extends Authenticatable
The AccountUser has roles trait. AccountUser 具有角色特征。
AccountUser {
use \Spatie\Permission\Traits\HasRoles;
I assign roles to Account:我将角色分配给帐户:
$account->assignRole('writer');
Now I want middleware to use Account instead of User model for check the permissions现在我希望中间件使用帐户而不是用户 model 来检查权限
['middleware' => ['permission:publish articles']
The question is: how to stay User Authenticatable and make AccountUser Roleble at the same time问题是:如何保持 User Authenticatable 并同时使 AccountUser Roleble
You can you middleware in array:你可以在数组中使用中间件:
'middleware' => ['first','second']
That'll check both at time same time.这将同时检查两者。
Your route middleware may be like this:你的路由中间件可能是这样的:
'middleware' => ['role:writer','permission:publish articles']
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.