Laravel和Spatie和用户表相互冲突的权限方法
我们将Laravel Spatie权限作为文库来管理角色和权限。不幸的是,在实施此库之前,我们在用户表中有一个列作为管理权限的权限。但是现在,当我们实施此库时,它正在与库相抵触。我们尝试重命名为图书馆工作正常的现有列。但是,由于现有列上有全流量,因此在完整项目上实施此功能是不可能的。
当tryng访问角色权限
$role->permissions
时检查权限不可能。 任何人都可以帮助我如何在任何解决方法的库中canoverrry canoverrry。
We are using laravel spatie permissions as the library to manage the role and permissions. Unfortunately before implementation of this library we were having a column in user table as permissions where we were managing the permissions. But now when we implemented this library it is getting conflicted with the library. We tried renaming the existing column that works fine for the library. But implementing this at complete project is impossible as there is full flow working on existing column.
when tryng to access the permissions of role :
$role->permissions
It returns the current db value and that make checking permission impossible.
Can anyone please help me how we canoverride the function in the library of any workaround this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只需更改 laravel/spatie/spatie 函数名称。
步骤1:在我们的应用程序目录中创建一个性状
,让我们创建一个新的目录并命名其权限,并创建一个新文件,即
haspermissionstrait.php
。已经建立了一个很好的小特质来处理用户关系。回到我们的用户模型中,只需导入这个特征,我们就可以了。app/user.php
现在转到
haspermissionstrait.php
,然后将其添加到其中。app/permissions/haspermissionstrait.php
现在将
权限>更改为
userrolepermissions
和在任何地方使用它。现在,我们可以使用
$ user-> userrololepermissions
使用Laravel Eloquent用户
访问。Just change laravel/spatie functions name.
Step 1: Creating a Trait
Inside our app directory, let’s create a new directory and name it Permissions and create a new file namely
HasPermissionsTrait.php
. A nice little trait has been set up to handle user relations. Back in our User model, just import this trait and we’re good to go.app/User.php
Now go to
HasPermissionsTrait.php
and add this to it.App/Permissions/HasPermissionsTrait.php
Now change
permissions
touserRolePermissions
and wherever uses it.And now we can access using
$user->userRolePermissions
with Laravel EloquentUser
.在先决条件部分,
在安装说明中,您将看到必须将 HasRoles 特征添加到用户模型中才能启用此包的功能。
因此,典型的基本用户模型将具有以下基本的最低要求:
In Prerequisites Section ,
In the Installation instructions you'll see that the HasRoles trait must be added to the User model to enable this package's features.
Thus, a typical basic User model would have these basic minimum requirements: