Reputation: 81
Hello I have an if that validates the access to the user according to the Role Currently I have it like this but I want to change the access to 2 roles.
My original variable is this:
if ($user->hasRole('Delivery Guy')) {
.... rest of the code.
I need that if to be something like this, try this but it doesn't work.
if ($user->hasRole('Delivery Guy' || 'Store Owner')) {
I need that if to allow access with both roles.
Thanks!
Upvotes: 0
Views: 2174
Reputation: 1302
You can use any of the following solutions.
$user->hasRole(['Delivery Guy', 'Store Owner']);
$user->hasAnyRole(['Delivery Guy', 'Store Owner']);
$user->hasAnyRole('Delivery Guy', 'Store Owner');
Read More about Roles/Permissions
Hope this will be useful.
Upvotes: 2
Reputation: 1
Use this code
if ($user->hasRole(['Delivery Guy', 'Store Owner'])) {
}
OR
if ($user->hasRole('Delivery Guy') || $user->hasRole('Store Owner')) {
}
Upvotes: -1
Reputation: 81
I found the solution thanks
if ($user->hasRole(['Delivery Guy', 'Store Owner'])) {
Upvotes: 1