Skip to main content

After Filament 5.12.1, a CreateAction for Another Model Needs That Model's Policy

Two admin-panel page headers on a dark background. The ADMIN header shows Edit and an emerald Issue refund button. The SUPPORT AGENT header shows Edit and an empty dashed slot with a red dot where Issue refund was, like a Filament 5.12.1 create action hidden from a support agent

I built a help desk panel on Filament 5.12.0, upgraded it to 5.12.1 and ran its tests.

Four of the failures were the same button.

Issue Refund (Tests\Feature\IssueRefund)
 ✘ Agent sees issue refund on the ticket page
   │ Failed asserting that an action with name [issueRefund] is visible on the [App\Filament\Resources\Tickets\Pages\ViewTicket] component.
   │ …
 ✘ Agent issues a refund from the ticket page
 ✔ Admin sees issue refund on the ticket page
 ✘ Agent sees issue refund when refund policy has no create method
 ✘ Agent sees issue refund under strict mode when refund policy has no create method

“Issue refund” was gone from the support agent’s ticket page.

The admin still had it.

The last two tests give Refund a policy without create(). The second also turns on strict mode. Both passed on 5.12.0. Trap 2 comes back to them.

Filament 5.12.1 shipped on November 28 with fixes for nine security advisories. Filament 4.17.1 shipped the same day with the same change. Filament 3 doesn’t have the change. Upgrading that day was the right call.

But nothing in the release notes says a button is about to disappear, and the docs still say a missing policy allows the action.

The panel runs on a fresh Laravel 13.45 app. I re-ran everything on 5.12.4, the latest patch as of December 3. Every output below comes from runs on 5.12.0, 5.12.1 or 5.12.4.

The setup

It’s the same help desk as the rest of this blog, now with a Filament admin panel. TicketResource has a View page, and its header carries an “Issue refund” action that creates a Refund for the ticket:

// app/Filament/Resources/Tickets/Pages/ViewTicket.php
use App\Models\Refund;
use Filament\Actions\CreateAction;
use Filament\Actions\EditAction;
use Filament\Forms\Components\TextInput;

protected function getHeaderActions(): array
{
    return [
        EditAction::make(),
        CreateAction::make('issueRefund')
            ->label('Issue refund')
            ->model(Refund::class)
            ->schema([
                TextInput::make('amount')->numeric()->required(),
                TextInput::make('reason')->required(),
            ])
            ->mutateDataUsing(function (array $data): array {
                $data['ticket_id'] = $this->getRecord()->getKey();

                return $data;
            }),
    ];
}

The ticket also has a Refunds relation manager, and finance has a Refunds page of its own.

A TicketPolicy lets any staff member view, create and update tickets. There’s no RefundPolicy yet.

Staff are support agents, and some of them are trainees who shouldn’t issue refunds yet. Nothing in the panel tells the two apart.

Admins pass everything through a Gate::before:

// app/Providers/AppServiceProvider.php
Gate::before(fn (User $user): ?bool => $user->is_admin ? true : null);

On 5.12.0 the support agent sees “Issue refund” because they can create tickets. So does every trainee. That is the bug 5.12.1 fixed.

What 5.12.1 changed

PR #21112, “authorize create actions against their model”, is a bug fix that shipped inside the security release.

Before it, every CreateAction on a resource page asked the page’s resource. TicketPolicy::create() decided who saw “Issue refund”. Anyone allowed to create a ticket was allowed to issue a refund, whatever a RefundPolicy said.

The fix asks the action’s own model. Here is the new branch in Page.php at v5.12.1:

$action instanceof CreateAction => ($action->getModel() === static::getResource()::getModel())
    ? static::getResource()::getCreateAuthorizationResponse()
    : Gate::inspect('create', $action->getModel()),

Same model: nothing changes. Another model: Laravel’s Gate::inspect(), called directly.

The PR body says what that means for a model with no policy. Cross-model actions without a policy or Gate grant “are denied instead of inheriting the owner model’s authorization.”

The denial is deliberate and correct, but only the PR body says so.

The release notes list the PR title, the same way they list the other 93 entries. No docs page changed.

Which create actions this hits

RelationManager.php and ManageRelatedRecords.php got the same branch. What counts as “the same model” depends on the page:

  • On a resource page, it’s the resource’s model: Ticket on ViewTicket.
  • On a relation manager or a ManageRelatedRecords page, it’s the related model: Refund on the Refunds relation manager.

So the Refunds relation manager’s own create button is a same-model create, and Filament’s own check still decides it. “Issue refund” in the ticket header is cross-model. So is a “Log call” CreateAction in a customer page’s header.

An explicit authorize() on the action skips the branch either way. A custom page inside a resource extends the same Page class, so its create actions reach the branch too. Standalone panel pages, widgets, standalone Livewire components and a plain Action::make() that creates a refund don’t.

None of those gets a default check at all. So don’t move “Issue refund” into a widget to get the button back. In a widget, the trainee sees it and creates the refund, even with a RefundPolicy whose create() returns false for them:

 ✔ Trainee sees issue refund in a widget when refund policy denies create
 ✔ Trainee issues a refund from a widget when refund policy denies create

Two rules on one ticket

Filament has its own authorization helper, get_authorization_response(). Every other CRUD action still goes through it.

When the policy or its method is missing, the helper throws in strict mode. Outside strict mode, it runs your Gate::before callbacks and allows the action unless one of them says no.

The resource docs still state that rule:

By default, Filament allows an operation when its model policy or policy method is missing, unless a Gate before callback denies it.

Laravel’s Gate has the opposite rule.

No policy and no defined ability means deny.

Here are both rules, asked about Refund for the same two users, beside a real GET of the ticket page on 5.12.4:

agent: GET /admin/tickets/1 -> 200, "Issue refund" in HTML: 0 time(s)
agent: Filament\get_authorization_response('create', Refund::class) -> allowed
agent: Gate::inspect('create', Refund::class) -> denied

admin: GET /admin/tickets/1 -> 200, "Issue refund" in HTML: 1 time(s)
admin: Filament\get_authorization_response('create', Refund::class) -> allowed
admin: Gate::inspect('create', Refund::class) -> allowed

On 5.12.0 the helper and the Gate give those same answers, but the page never asks either one about Refund. Both users see the button.

The Refunds relation manager on the same ticket goes through Filament’s helper, with the same missing policy. Its create button lives on the ticket’s edit page, because relation managers on a view page are read-only.

On 5.12.4 the same support agent loses the header button and still creates a refund from the relation manager:

 ✘ Agent sees issue refund on the ticket page
 …
 ✔ Agent creates a refund from the relation manager

Filament Mastery’s authorization guide, tagged for v3 to v5, mixes the two up: “If no policy is registered for a model, Laravel allows the action.” Laravel denies. Filament’s helper allows.

For a create action on another model, 5.12.1 gives you Laravel’s answer.

Trap 1: who loses the button depends on your admin setup

The admin kept “Issue refund” because Gate::before returns true before the Gate looks for a policy.

If that’s how your admins work, an admin click-through after the upgrade shows nothing wrong.

Admins whose access comes from a policy’s before(), or from role checks inside each policy, lose the button too. I ran four admin setups, plus one support agent, on both versions:

filament/filament v5.12.4

admin, Gate::before, no RefundPolicy: visible
admin, RefundPolicy::before() but no create(), no Gate::before: hidden
admin, no Gate::before, no RefundPolicy: hidden
admin, Gate::after, no Gate::before, no RefundPolicy: visible
agent, TicketPolicy::create() false, RefundPolicy::create() true: visible

On 5.12.0 all four admins saw the button.

Spatie’s permission docs describe three super-admin setups and recommend the global ones: Gate::before (row one) or Gate::after (row four). Both keep the button. Their third setup, a before() in each policy, is row two.

In the second row, the policy’s before() never runs. Laravel only calls a policy’s before() when the policy has the method the Gate is checking. No create(), no before().

The third row is an admin whose rights live in role checks inside each TicketPolicy method. Nothing answers for Refund, so the Gate denies.

Row five goes the other way. In a desk where customers open tickets and staff can’t create them, 5.12.0 hid “Issue refund” from the agent. On 5.12.4 the button appears, because the refund rule answers now.

Check who gains a button as well as who loses one.

Trap 2: strict mode stays quiet

Strict mode exists to catch a missing policy method.

The panel docs say it throws “if the policy or policy method does not exist.”

The last two tests from the opening give Refund a policy with viewAny() and view() but no create(). The second also turns strict mode on. It loads the page inside a try that fails the test if anything throws, then checks the button.

On 5.12.0 both passed, because the page asked TicketPolicy::create(), which exists.

On 5.12.1:

 ✘ Agent sees issue refund when refund policy has no create method
 ✘ Agent sees issue refund under strict mode when refund policy has no create method
   │ Failed asserting that an action with name [issueRefund] is visible on the [App\Filament\Resources\Tickets\Pages\ViewTicket] component.

The page loaded. The failure is the button check, not a LogicException. The button just disappears, and nothing tells you why.

The throw lives in Filament’s helper, and the cross-model branch never calls it.

The fix is Fix A, below: add create() to the policy you already have.

Fix it

Two fixes bring the button back. They differ in which rule decides who sees it.

Fix A: give the model its own create rule

Reach for this one first. Refunds are the write you guard hardest, in this panel and in the AI that answers the same tickets.

Write the rule you mean. On this desk, a can_issue_refunds flag on the user separates agents who refund from trainees who don’t:

// app/Policies/RefundPolicy.php
namespace App\Policies;

use App\Models\User;

class RefundPolicy
{
    public function create(User $user): bool
    {
        return $user->can_issue_refunds;
    }
}

With it in place on 5.12.4, the agent gets the button back and the trainee doesn’t:

Refund Button Visibility (Tests\Feature\RefundButtonVisibility)
 ✔ Agent who issues refunds sees the button
 ✔ Trainee does not see the button

Don’t generate the policy with php artisan make:policy RefundPolicy --model=Refund and leave the stub. The stub writes return false; into every method:

$ grep -n -E "function|return" app/Policies/RefundPolicy.php
14:    public function viewAny(User $user): bool
16:        return false;
22:    public function view(User $user, Refund $refund): bool
24:        return false;
30:    public function create(User $user): bool
32:        return false;
…

Once a RefundPolicy exists, Filament asks its methods about Refund, and every stub method returns false. With the stub in place, the support agent loses the Refunds relation manager and the Refunds page:

agent, no RefundPolicy: Refunds relation manager on the ticket: shown; Refunds resource page: HTTP 200
agent, make:policy stub: Refunds relation manager on the ticket: hidden; Refunds resource page: HTTP 403

Under strict mode, a create()-only policy breaks the whole ticket page, because the page asks viewAny() on Refund before it shows the Refunds relation manager:

strict mode, create()-only RefundPolicy: GET ticket page -> LogicException: Strict authorization mode is enabled, but no [viewAny()] method was found on [App\Policies\RefundPolicy].

So under strict mode, write every method your panel checks for Refund, each with a rule you mean.

Fix B: authorize the action against the ticket

If your refund rule really is “whoever can work this ticket”, put that on the action:

CreateAction::make('issueRefund')
    // ...
    ->authorize(fn (): bool => auth()->user()->can('update', $this->getRecord())),

An explicit authorize() replaces the page default, so the new branch never runs (CanBeAuthorized.php). It passes on 5.12.4:

 ✔ Fix b explicit authorize on the action

Don’t shorten it to ->authorize('update'). The string form asks the Gate about Refund, not the ticket, and the button disappears again:

agent, ->authorize('update'): hidden

Fix B puts back, by hand, what #21112 removed: refunds follow a ticket rule again.

That’s fine when the ticket rule is your refund rule. If refunds need a finance role or an amount limit, it’s wrong, and Fix A is the answer.

Find yours before your support agents do

The test that catches this acts as a user who should see the button and a user who shouldn’t.

A test that logs in as an admin who passes Gate::before stays green on both versions.

It reads the can_issue_refunds flag from Fix A. Swap in whatever separates your two users.

// tests/Feature/RefundButtonVisibilityTest.php
namespace Tests\Feature;

use App\Filament\Resources\Tickets\Pages\ViewTicket;
use App\Models\Ticket;
use App\Models\User;
use Filament\Facades\Filament;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Livewire\Livewire;
use Tests\TestCase;

class RefundButtonVisibilityTest extends TestCase
{
    use RefreshDatabase;

    protected function setUp(): void
    {
        parent::setUp();

        Filament::setCurrentPanel('admin');
    }

    public function test_agent_who_issues_refunds_sees_the_button(): void
    {
        $this->actingAs(User::factory()->create(['can_issue_refunds' => true]));

        Livewire::test(ViewTicket::class, ['record' => Ticket::factory()->create()->getRouteKey()])
            ->assertActionVisible('issueRefund');
    }

    public function test_trainee_does_not_see_the_button(): void
    {
        $this->actingAs(User::factory()->create(['can_issue_refunds' => false]));

        Livewire::test(ViewTicket::class, ['record' => Ticket::factory()->create()->getRouteKey()])
            ->assertActionHidden('issueRefund');
    }
}

On 5.12.4 with no RefundPolicy, the first test fails:

 ✘ Agent who issues refunds sees the button
   │ Failed asserting that an action with name [issueRefund] is visible on the [App\Filament\Resources\Tickets\Pages\ViewTicket] component.
 ✔ Trainee does not see the button

On 5.12.0 the second one fails, because TicketPolicy::create() let the trainee refund:

 ✔ Agent who issues refunds sees the button
 ✘ Trainee does not see the button
   │ Failed asserting that an action with name [issueRefund] is hidden on the [App\Filament\Resources\Tickets\Pages\ViewTicket] component.

That second failure is the hole #21112 closed. Keep both tests, and the next change to this check shows up in CI.

To find candidates, grep for two patterns: a CreateAction chain with ->model() within 15 lines, and subclasses.

$ grep -rn -A15 "CreateAction::make" app/Filament | grep -e "->model("
app/Filament/Resources/Tickets/Pages/ViewTicket.php-22-                ->model(Refund::class)

$ grep -rn "extends CreateAction" app
[exit 1]

Each hit is a candidate to check. A model set through configureUsing(), or more than 15 lines below CreateAction::make, won’t show up, so an empty grep doesn’t clear you. The visibility test does.

Serve the same refund action over MCP and it fails the other way: the tool stays listed to every user until you hide it.

Take 5.12.4, not 5.12.1

The same release shipped regressions, and Filament has fixed them. 5.12.2 fixed two: a JavaScript TypeError that stopped Select search (#21192), and fillForm() dropping rich editor content in tests (#21191). Two more hit this desk.

A Select::relationship() crashes on save when the related model casts its key to a BackedEnum (#21202, fixed in 5.12.3):

 ✘ Agent creates a ticket in a department
   │ Error: Object of class App\Enums\DepartmentCode could not be converted to string
   │ support-desk/vendor/filament/forms/src/Components/Select.php:895

5.12.1 also gave text fields Laravel’s string rule.

A plain TextInput that holds an integer fails validation, even on an untouched save (#21210, fixed in 5.12.4). The ticket form’s order_number is an integer column in a hand-written TextInput:

 ✘ Agent saves an existing ticket without changes
   │ Component has errors: "data.order_number" => ["The order number field must be a string."]

Filament’s resource generator adds ->numeric() to integer columns, so generated forms skip this one.

On 5.12.4 both tests pass.

On Filament 4, the fixes for these two shipped in 4.17.3 and 4.17.4, so take 4.17.4.

Composer 2.9 and later won’t resolve 5.12.0 any more on require or update:

- Root composer.json requires filament/filament 5.12.0 (exact version match: 5.12.0 or 5.12.0.0), found filament/filament[v5.12.0] but these were not loaded, because they are affected by security advisories ("PKSA-q7p6-368s-19tg", "PKSA-75ty-vbr6-frrn"). …

But composer install from an old lock file still deploys it.

Run composer audit in CI.

A tenancy gap 5.12.4 still leaves open

A line in the 5.12.1 notes reads like a tenancy fix: #21095, “scope resource queries through their own tenant relationship”. It fixes resources that share a model. It doesn’t close the relation manager gap in Filament 5.10’s advisory, GHSA-6p72-cx74-63f5.

On 5.12.4, a ticket moved to another team still takes a refund from a Refunds relation manager that was open before the move:

 ✘ Relation manager refuses a refund after the ticket moves team

If your panel uses tenancy, check the owner record in canViewForRecord(), as the security docs say. Filament runs it on every request to the relation manager:

// app/Filament/Resources/Tickets/RelationManagers/RefundsRelationManager.php
use Filament\Facades\Filament;
use Illuminate\Database\Eloquent\Model;

public static function canViewForRecord(Model $ownerRecord, string $pageClass): bool
{
    $tenant = Filament::getTenant();

    if ($tenant && ! $ownerRecord->team()->is($tenant)) {
        return false;
    }

    return parent::canViewForRecord($ownerRecord, $pageClass);
}

On 5.12.4, the next request after the move gets a 403, and the relation manager writes no refund:

 ✔ Owner check refuses a refund after the ticket moves team
 ✔ Owner check answers the next request with 403 after the move

Should you upgrade?

Yes. Today, to 5.12.4, or 4.17.4 on Filament 4.

The advisories are real, and #21112 closes the hole the trainee test shows.

A security upgrade isn’t finished when Composer exits. The PHP2Shell patch needed a check after deploy too, on the process still serving requests.

Before 5.12.4 goes to production, give every model that a CreateAction creates its own create() rule, or an explicit authorize() you chose on purpose.

Keep a visibility test for the user who should see each button and the user who shouldn’t.

The next hardening release can move a check again.

Your suite will tell you before your support agents do.