Hi Povilas || Anyone else who sees this and can help,
I have a project where I am trying to use the comma seperated value to determine where multiple roles ('super-admin' and 'admin' roles, in this case) should have access to a particular route. Unfortunately, only one role (at a time) is going through, not more than one.
I think the problem is in your middleware.
Since you use foreach - you're basically saying "if user doesn't have one of the roles in the array - abort".
I'd rather compare the arrays of current user role and the allowed roles :
Hi Povilas || Anyone else who sees this and can help,
I have a project where I am trying to use the comma seperated value to determine where multiple roles ('super-admin' and 'admin' roles, in this case) should have access to a particular route. Unfortunately, only one role (at a time) is going through, not more than one.
My test for this feature, keeps failing.
Here are my codes below.
Kindly help urgently. Thanks in advance.
C:...\tests\Feature\CategoryTest.php
C:...\app\Http\Middleware\RoleMiddleware.php
C:...\routes\api.php
I think the problem is in your middleware. Since you use foreach - you're basically saying "if user doesn't have one of the roles in the array - abort".
I'd rather compare the arrays of current user role and the allowed roles :
Thanks for your reply. I have already concluded the app using a verbose pattern.
I will apply your pattern in my next project that is coming up this month.