Skip to content

Change Table cacheAction method visibility to public#19457

Open
mathieutu wants to merge 1 commit intofilamentphp:4.xfrom
mathieutu:patch-5
Open

Change Table cacheAction method visibility to public#19457
mathieutu wants to merge 1 commit intofilamentphp:4.xfrom
mathieutu:patch-5

Conversation

@mathieutu
Copy link
Contributor

@mathieutu mathieutu commented Mar 9, 2026

Description

Context

When working with Filament tables, it's possible to define a recordAction to trigger an action when clicking on a row. However, this action must be registered beforehand (e.g. via recordActions, which renders an unwanted button in the row).

The ideal approach would be to pass an Action instance directly to recordAction(), but as an intermediate step, being able to register an action via cacheAction() from outside the Table class is already a significant improvement.

Problem

The cacheAction() method on Table is protected, making it impossible to call it from a Livewire component or a resource page without resorting to workarounds.

The only way to achieve the desired behavior was to use a closure bound to $table to bypass visibility:

(fn () => $this->cacheAction(
    Action::make('show_answers')
        ->label('Foo')
        ->schema(fn ($record) => [
            // ...
        ])
        ->action(fn ($record, $data) => /* ... */)
))->call($table);

return $table
    ->query(/* ... */)
    ->columns([/* ... */])
    ->recordAction('show_answers');

Solution

Make cacheAction() public, allowing it to be called directly on the Table instance:

$table->cacheAction(
    Action::make('show_answers')
        ->label('Foo')
        ->schema(fn ($record) => [
            // ...
        ])
        ->action(fn ($record, $data) => /* ... */)
);

return $table
    ->query(/* ... */)
    ->columns([/* ... */])
    ->recordAction('show_answers');

Future improvements

A natural follow-up would be to allow passing an Action instance directly to recordAction(), removing the need to call cacheAction() altogether. This PR is a quick win in that direction, but also unlocking broader use cases.

Visual changes

None

Functional changes

  • Code style has been fixed by running the composer cs command.
  • Changes have been tested to not break existing functionality.
  • Documentation is up-to-date.

Signed-off-by: Mathieu TUDISCO <oss@mathieutu.dev>
@mathieutu
Copy link
Contributor Author

Tests failing for an unrelated reason.

@danharrin danharrin added enhancement New feature or request pending changes labels Mar 9, 2026
@danharrin danharrin added this to the v4 milestone Mar 9, 2026
Copy link
Member

@danharrin danharrin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer allow passing an Action instance directly to recordAction() instead of making this public

@github-project-automation github-project-automation bot moved this from Todo to In Progress in Roadmap Mar 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request pending changes

Projects

Status: In Progress

Development

Successfully merging this pull request may close these issues.

2 participants