web / api roles and permissions headache! #2421
-
Hi Guys! I cannot figure this out. In my seeder I created:
I created ADMIN roles for
I assign user 1 the ADMIN role:
So, my user 1 has ADMIN role which has a separate set of permissions for guards: Now , in my unit tests:
I don't understand why test 1 fails ??? Thanks! |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 5 replies
-
That only assign |
Beta Was this translation helpful? Give feedback.
-
In your sample code you're using However, if your app structure does NOT differentiate between guards when it comes to roles/permissions, (ie: if ALL your roles/permissions are the SAME for ALL guards), you could try adding this override to your User model, and then you'd only need to create roles/permissions for that single guard_name, not duplicating them: protected function getDefaultGuardName(): string { return 'web'; } |
Beta Was this translation helpful? Give feedback.
-
Thanks drbyte but still same problem, only the below returns true
my ROLES table looks like this:
my MODEL_HAS_ROLES table looks like this:
Now, I manually editted MODEL_HAS_ROLES and added new row:
..and everything works perfectly, both your suggestion: Looks like I need to call:
|
Beta Was this translation helpful? Give feedback.
$role = Role::findByName(Roles::ADMIN, 'api');
$user->assignRole($role);
Edit: I think you have to pass an attributes array to findByName...