Laratrust is a laravel package that lets you handle very easily roles and permission inside your application.
laratrust by default make use of users relation but sometimes you wish not to use users relation in order to do so there are few steps to follow.
step 1: install the package using composer.
composer require santigarcor/laratrust
step 2: public the configuration files.
php artisan vendor:publish --tag="laratrust"
step: 3 Now before setting up laratrust you have to make a few changes to config/laratrust.php in laratust.php file make changes to tables array like so
'tables' => [
'roles' => 'roles',
'permissions' => 'permissions',
'teams' => 'teams',
'role_user' => 'role_admin',
'permission_user' => 'permission_admin',
'permission_role' => 'permission_role',
],
Note: do not change keys of tables array let it be as it is.
step: 4 And now a slight change to the foreign keys array instead of using user_id it should now be admin_id like so.
'foreign_keys' => [
'user' => 'admin_id',
'role' => 'role_id',
'permission' => 'permission_id',
'team' => 'team_id',
],
now you are all set to use laratrust with admin table instead of users table.
Run the following artisan command to setup your laratrust migration.
php artisan laratrust:setup
in migration of laratrust you would be able to see that migration is setup for admin table now simply migrate using.
php artisan migrate
and that’s all for using laratrust with a different relation than users.
For further details please go to laratrust official site https://laratrust.santigarcor.me
Thank you
Top comments (0)