© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•9mo ago•
18 replies
KennY_Thugs

ViewAny Policy with user HasRoles

Hello someone can explain if i can hide SuperAdmin role to Admin Role in UsersTable with Policy.


Like this:


public function viewAny(User $user): bool
    {
        // Check if the user has the 'view any users' permission
        if ($user->hasRole(['SuperAdmin'])) {
            return true;
        } else if ($user->hasRole(['Admin'])) {
            // Example: allow Admins to view any users but dont see SuperAdmin
            return true;
        } else {
            return false;
        }
    }
public function viewAny(User $user): bool
    {
        // Check if the user has the 'view any users' permission
        if ($user->hasRole(['SuperAdmin'])) {
            return true;
        } else if ($user->hasRole(['Admin'])) {
            // Example: allow Admins to view any users but dont see SuperAdmin
            return true;
        } else {
            return false;
        }
    }
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Authorization: view policy and ViewAny policy wont work separated
FilamentFFilament / ❓┊help
5mo ago
User Policy not observed
FilamentFFilament / ❓┊help
3y ago
Can't edit a resource if viewAny() is false (Model Policy)
FilamentFFilament / ❓┊help
3y ago
Why View Page needs viewAny policy role to be true for viewing?
FilamentFFilament / ❓┊help
2y ago