1

UPDATE - SOLUTION I opened an issue on their github page: https://github.com/spatie/laravel-permission/issues/1398#issuecomment-594032058

All I had to do is change the change the 'model_morph_key' type, in the migrations, to mach the type of my User model's primary key.

This is my first post on Stackoverflow, so apologies for the poor structure

I'm using this Laravel package: https://github.com/spatie/laravel-permission

I'm trying to give Admin permissions to a specific user by assigning a role to the user.

The issue: The role/permissions are assigned to the entire User Model instead of that specific user.

Has anyone faced anything similar? I wasn't able to find anything online. Keep in mind that my User Model is not using an auto-increment a number as a unieque ID. Could this be the cause of the issue?

Code

// Creates Admin Role 
$admin_role = Role::create(['name' => 'Admin']);

// Assigning Permissions to Roles
$admin_role->givePermissionTo($access_admin_panel);
$admin_role->givePermissionTo($change_user_roles);

// Assigning role to user
auth()->user()->assignRole('Admin');

Thanks.

apokryfos
  • 38,771
  • 9
  • 70
  • 114
user263104
  • 11
  • 1
  • 4
  • Welcome to StackOverflow! Please post as well the code that you are currently using to assign the role (you can add it by editing your question) – mdexp Mar 03 '20 at 09:42
  • You can use this package on different Models. So the package stores additionaly the relevant model for the permission. Maybe you missed another table where the permission is directly bind to a specific user. – Brotzka Mar 03 '20 at 09:46
  • @Brotzka I used all the migrations provided by the package. These create the role_has_permissions model_has_roles model_has_permissions roles permissions' – user263104 Mar 03 '20 at 09:51
  • What are you using instead of the auto-increment ID? A manual ID, an UUID, the username or something else? – mdexp Mar 03 '20 at 23:08
  • Thank you everyone for the response. I opened an issue on github: https://github.com/spatie/laravel-permission/issues/1398#issuecomment-594032058 and was able to quickly figure out the solution. – user263104 Mar 04 '20 at 07:36

0 Answers0