You added a policy and half the Filament resource disappeared
Filament asks your policy one question per action. When the method exists it obeys it; when the method is missing, it allows the action. A generated policy and a tidied-up policy fail in opposite directions.
ON THIS PAGE
A policy for one rule, and the panel changes shape
Editors should only be allowed to edit posts. That is the whole requirement, so you run php artisan make:policy PostPolicy --model=Post, fill in the three methods you care about, and reload the panel.
The list page still works. Editing still works. But the New post button has gone, the delete action has gone from every row, and the support team is asking why they can no longer do half of what they did yesterday. Meanwhile, the bulk Delete selected action at the top of the table is still there, and it still works.
None of that is a Filament bug. It is one rule, applied to a file that Artisan wrote more of than you noticed.
The rule: a missing method is a yes
Every Filament resource checks your model policy before it shows a page, a button or an action. The decision is made in a helper that does, in order:
- Look up the policy for the model, through Laravel's normal policy discovery.
- If the policy exists and has a method named after the ability —
viewAny,create,update,delete,deleteAnyand so on — call it and obey the answer. - Otherwise, run any global
Gate::before()callbacks. If one returnsfalse, deny. If none does, allow.
The Filament docs say it in one sentence: by default, Filament allows an operation when its model policy or policy method is missing. No policy at all means everything is allowed. That is why a brand-new resource shows every button before you have written a line of authorisation.
Why the generated stub hides things
Now look at what make:policy --model=Post actually writes. Every method is a deny:
class PostPolicy
{
public function viewAny(User $user): bool
{
return false;
}
public function create(User $user): bool
{
return false;
}
public function delete(User $user, Post $post): bool
{
return false;
}
// view, update, restore, forceDelete: all return false
}
The moment that file exists in app/Policies, Laravel discovers it by name and Filament starts asking it. Every method you did not edit is a method that now says no. You changed viewAny, view and update to return true, so those work; create and delete still return false, so their buttons disappear.
That half is the safe failure. It is annoying, but nobody can do anything you did not allow.
Why bulk delete survived
The other half is not safe. The generated stub has seven methods, and deleteAny is not one of them. Filament's bulk delete does not loop through delete() for every selected row — that would be one policy call per record — so it asks deleteAny() once instead. There is no such method on the policy, so the rule from earlier applies: missing means allowed.
Here is what the resource reported in a scratch application with exactly that policy — viewAny, view and update returning true, everything else left as generated:
canViewAny => true
canCreate => false
canEdit => true
canDelete => false
canDeleteAny => true
And this is what happened when the bulk action ran against three selected posts:
posts left after bulk delete: 0
The per-row delete is forbidden. The bulk delete removes every row you tick.
Deleting the stub makes it worse
The instinct, once the buttons disappear, is to clean up: delete the methods you "do not use yet" so the policy only contains the rules you have actually thought about. Remove delete() from the policy above and ask again:
no delete() method, canDelete => true
You have not removed a rule. You have converted "nobody may delete" into "everybody may delete".
There is a second trap behind this one. A policy before() method looks like the place to put a blanket rule, such as blocking suspended accounts:
public function before(User $user, string $ability): ?bool
{
return $user->is_suspended ? false : null;
}
Laravel's own documentation warns that a policy's before method is not called when the class has no method matching the ability. Filament's fallback only consults global Gate::before() callbacks, not the policy's own before(). So for a suspended user:
policy before() false: canEdit => false, canDelete (no method) => true
Gate::before false: canDelete (no method) => false
If the rule must hold for actions you have not written methods for, register it with Gate::before() in a service provider, not in the policy.
Make missing methods loud
Filament has a switch for exactly this. Turn on strict authorisation in the panel provider:
public function panel(Panel $panel): Panel
{
return $panel
// ...
->strictAuthorization();
}
With it on, a missing policy or a missing method throws instead of quietly allowing. Against the trimmed policy above, the first page load says precisely what is absent:
LogicException: Strict authorization mode is enabled, but no [delete()] method was found on [App\Policies\PostPolicy].
LogicException: Strict authorization mode is enabled, but no [deleteAny()] method was found on [App\Policies\PostPolicy].
That is the error you want to meet on your own machine, not in an incident review.
For bulk actions where one blanket answer is not good enough — "editors may delete their own drafts" — Filament also offers authorizeIndividualRecords() on the bulk action. It checks each selected record against the per-record policy method and skips the ones that fail.
Pin the answers in a test
Strict mode tells you a method is missing. It does not tell you the method says the right thing. The resource exposes the same checks the panel uses, so you can assert on them directly, with no browser and no Livewire round trip:
it('does not let editors bulk delete posts', function () {
$this->actingAs(User::factory()->create());
Filament::setCurrentPanel('admin');
expect(PostResource::canViewAny())->toBeTrue()
->and(PostResource::canDeleteAny())->toBeFalse();
});
With a single panel, setCurrentPanel() is optional — outside a request Filament falls back to the default panel. Once you have several panels with different guards, set it explicitly so the test checks the panel you mean. Write one of these per role you care about. They run in milliseconds and they fail the day someone deletes a method to make a button come back.
What to change
Open every policy that has a Filament resource in front of it and list the abilities Filament will ask about: viewAny, view, create, update, delete, deleteAny, restore, restoreAny, forceDelete, forceDeleteAny, replicate and reorder. Each one either has a method with a deliberate answer, or is allowed for every panel user. There is no third option.
Add deleteAny() to any policy generated by make:policy, because the stub does not include it and bulk delete depends on it. Move blanket denials out of policy before() methods into Gate::before(). Then enable strictAuthorization() on the panel, load every resource once, and fix each exception it throws. When the panel loads cleanly with strict mode on, every button you can see is one your policy chose to show.