© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
23 replies
Prodex

Policy not enforced

Hi, I created a "LocationPolicy" that looks like this:
    public function view(User $user, Location $location)
    {
        $allowedLocations = $user->locations;
        return $allowedLocations->contains($location);
    }
    public function view(User $user, Location $location)
    {
        $allowedLocations = $user->locations;
        return $allowedLocations->contains($location);
    }


and registered it like so:
    protected $policies = [
        User::class => LocationPolicy::class
    ];

    public function boot(): void
    {
        $this->registerPolicies();
    }
    protected $policies = [
        User::class => LocationPolicy::class
    ];

    public function boot(): void
    {
        $this->registerPolicies();
    }


But this policy doesn't seem to be enforced when using a select multiple:
                    Forms\Components\Select::make('locations')
                                           ->label(trans('locations.plural'))
                                           ->multiple()
                                           ->searchable()
                                           ->relationship('locations', 'name')
                                           ->preload()
                                           ->required(),
                    Forms\Components\Select::make('locations')
                                           ->label(trans('locations.plural'))
                                           ->multiple()
                                           ->searchable()
                                           ->relationship('locations', 'name')
                                           ->preload()
                                           ->required(),


Currently the user can still choose all locations, where it should only be those relateded with the user model.

What am I missing here?
Thank you!
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

User Policy not observed
FilamentFFilament / ❓┊help
3y ago
Model Policy on page not working
FilamentFFilament / ❓┊help
2y ago
Policy not applying on custom action
FilamentFFilament / ❓┊help
2y ago
Translations plugin model not accepting Policy
FilamentFFilament / ❓┊help
3y ago