© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
18 replies
Pan

Custom Action

What I am trying to do:
I am trying to create a custom action like the AssociateAction however I want to customize it on my own form.

What I did:
I tried following this
https://filamentphp.com/docs/3.x/actions/modals#modal-forms, specifically this part
    ->action(function (array $data, Post $record): void {
        $record->author()->associate($data['authorId']);
        $record->save();
    })
    ->action(function (array $data, Post $record): void {
        $record->author()->associate($data['authorId']);
        $record->save();
    })

I've changed the $record into $post and the author() into just
->user_id
->user_id
and right now I am testing it
->associate(1)
->associate(1)
by just passing an int to see if it works.

My issue/the error:
if I kept the
$post-user_id()->associate(1)
$post-user_id()->associate(1)
i get the error BadMethodCall
Call to undefined method App\Models\Equipment::user_id()
changing it into
post-user_id->associate(1)
post-user_id->associate(1)
i get the error Call to a member function associate() on null

Code:
    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('name')
            ->columns([
                Tables\Columns\TextColumn::make('name'),
            ])
            ->headerActions([
                Tables\Actions\Action::make('Borrow Test')
                    ->form([
                        Forms\Components\Select::make('name')
                            ->searchable()
                            ->options(Equipment::query()->pluck('name','barcode'))
                            //->getSearchResultsUsing(fn (string $search): array => Equipment::where('barcode', 'like', "%{$search}%")->limit(50)->pluck('name')->toArray())
                    ])
                    ->action(function (array $data, Equipment $post): void{
                        $post->user_id->associate(1);
                        $post->save();
                    })
          ])
    public function table(Table $table): Table
    {
        return $table
            ->recordTitleAttribute('name')
            ->columns([
                Tables\Columns\TextColumn::make('name'),
            ])
            ->headerActions([
                Tables\Actions\Action::make('Borrow Test')
                    ->form([
                        Forms\Components\Select::make('name')
                            ->searchable()
                            ->options(Equipment::query()->pluck('name','barcode'))
                            //->getSearchResultsUsing(fn (string $search): array => Equipment::where('barcode', 'like', "%{$search}%")->limit(50)->pluck('name')->toArray())
                    ])
                    ->action(function (array $data, Equipment $post): void{
                        $post->user_id->associate(1);
                        $post->save();
                    })
          ])

Ignore the other headerActions like AssociateAction and 'Borrow'

Thank you !!!!
Modals - Actions - Filament
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

ActionGroup Action caching custom view
FilamentFFilament / ❓┊help
9mo ago
Custom Action
FilamentFFilament / ❓┊help
3y ago
custom action
FilamentFFilament / ❓┊help
3y ago
Custom Action
FilamentFFilament / ❓┊help
3y ago