© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•13mo ago
sethbr11

View and ViewAny Permissions

I have a custom menu item on my backend which has this logic for visibility:
->visible(function () {
                        $location = Location::find(auth()->user()->location_id);
                        $canView = auth()->user()->can('view', $location);
                        $canViewAll = auth()->user()->can('viewAny', Location::class);
                        return $canView && !$canViewAll;
                    })
->visible(function () {
                        $location = Location::find(auth()->user()->location_id);
                        $canView = auth()->user()->can('view', $location);
                        $canViewAll = auth()->user()->can('viewAny', Location::class);
                        return $canView && !$canViewAll;
                    })

I did this so it doesn't show for super admins, who are able to see the actual page with all of the locations. This seems to work, but when I'm in as a role who has view permissions but not viewAny and I click on the menu item, I get a 403 page. I can't seem to figure out why I can't view the location page. This is my location policy:
/**
     * Determine whether the user can view any models.
     */
    public function viewAny(User $user): bool
    {
        return $user->can('view_any_location');
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(User $user, Location $location): bool
    {
        return $user->can('view_location');
    }
/**
     * Determine whether the user can view any models.
     */
    public function viewAny(User $user): bool
    {
        return $user->can('view_any_location');
    }

    /**
     * Determine whether the user can view the model.
     */
    public function view(User $user, Location $location): bool
    {
        return $user->can('view_location');
    }

Eventually I'd want to change this so it restricts it to only being able to view their location, but right now it's just not letting me access the page or any of the locations. Any help here?
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
Any solution other than scope for view override viewAny Permission?
FilamentFFilament / ❓┊help
5mo ago
Why View Page needs viewAny policy role to be true for viewing?
FilamentFFilament / ❓┊help
2y ago
Roles and permissions
FilamentFFilament / ❓┊help
2y ago