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.
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
.