Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

diazwatson's avatar

Custom action in resource page only works when in getHeaderActions([])

I have a resource page where I have created a couple of custom actions. The buttons appear but when I click nothing happens.

The only way they work is when I add my custom actions to the getHeaderActions([]) but obviously that duplicate the actions as well as it renders my custom actions in the header but that is not what I want.

namespace App\Filament\Play\Resources\GameResource\Pages;

use App\Filament\Play\Resources\GameResource;
use App\Models\Game;
use Filament\Actions\Action;
use Filament\Actions\StaticAction;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry\TextEntrySize;
use Filament\Resources\Concerns\Translatable;
use Filament\Resources\Pages\Page;
use Filament\Support\Enums\FontFamily;
use Filament\Support\Enums\IconPosition;
use Illuminate\Contracts\Support\Htmlable;
use Illuminate\Database\Eloquent\Collection;
use LaravelIdea\Helper\App\Models\_IH_Game_C;

class GameList extends Page
{
    use Translatable;

    protected static string $resource = GameResource::class;

    protected static string $view = 'filament.play.resources.game.pages.list';


    protected function getHeaderActions(): array
    {
        return [
//            $this->newGameAction(),
//            $this->joinGameAction(),
        ];
    }


    public function newGameAction()
    {
        $identifier = \App\Models\GameSession::generateIdentifier();

        return Action::make('new')
            ->label('New game')
            ->translateLabel()
            ->slideOver()
            ->modalSubmitActionLabel('Start')
            ->infolist([
                \Filament\Infolists\Components\TextEntry::make('Session identifier')
                    ->translateLabel()
                    ->copyable()
                    ->copyMessage('Copied!')
                    ->icon('heroicon-m-share')
                    ->iconPosition(IconPosition::After)
                    ->size(TextEntrySize::Large)
                    ->copyMessageDuration(1500)
                    ->helperText('Share this code with your friends to join the game.')
                    ->fontFamily(FontFamily::Mono)
                    ->state(
                        [
                            'identifier' => $identifier,
                        ]
                    ),
            ])
            ->action(function (\App\Actions\NewGameAction $newGameAction, $arguments) use ($identifier){
                $newGameAction->execute($arguments['game_id'], auth()->id(), $identifier);
            });
    }
...
0 likes
4 replies
diazwatson's avatar

Hi @aurawindsurfing thanks for looking at this.

You are right this is the way they are meant to be used but my page use these custom actions per record and adding them in getHeaderActions not only creates a top menu I don't need it but also doesn't make sense because as I mention, these actions should be executed per record.

This is how it looks: Screenshot 2024-04-24 at 10 01 29

Cien02's avatar

@diazwatson not sure if you are still looking for answer to this but to make it work you just need to update the action name to match the function name like this Action::make('newGame') for function name newGameAction())

1 like

Please or to participate in this conversation.