ViewAny Policy with user HasRoles
Hello someone can explain if i can hide SuperAdmin role to Admin Role in UsersTable with Policy.
Like this:
11 Replies
So that should be added in the 'view' not 'viewAny'
Thanks for your help and attention. But what i want is i have two Roles SuperAdmin and Admin and i want the SuperAdmin view all records and Admin view all records but dont see SuperAdmin.
I was trying with
And then i thought create another Resource UserSuperAdmin only for SuperAdmin and resource Users for Admin ?
You should look into global gates. Good example use case https://spatie.be/docs/laravel-permission/v6/basic-usage/super-admin
Defining a Super-Admin | laravel-permission
laravel-permission
Basically. You can bypass the policy entirely for certain roles by defining a Gate::before() or Gate::after()
Sorry i see this solution but i want to remove one row only and can see the other rows in the table users.
Example table users have
SuperAdmin View
Admin View
Hmm, you might need a combination of gates, policies and query scopes then.
i try this in UserResource:
But dont work 😟
Where are you using this?
I still think with the right scopes you won’t have to modify the query.
Try moving the logic into ->modifyQueryUsing() directly on the table.
Its working thanks guys for all attention and sorry for my English and the complications