FilamentF
Filament2y ago
Anik

custom actions dont trigger on table

What I am trying to do:
I am querying the data from a relationship and I need to update the pivot columns

What I did:
extended list record page
used table query for modifying query to relationship->getQuery()

My issue/the error:
Custom Actions dont work when using relationship->getQuery()

Code:
    public function table(Table $table): Table
    {
        return $table
            // action works but pivot data is not loaded ie cannot update invite_status
            // ->query(fn (): Builder => Events::whereHas('artists', function ($query) {
            //     $query->where('artists.id', Filament::auth()->user()->id);
            // }))
            // pivot data is loaded but Action dont trigger modal
            ->query(fn (): Builder => Filament::auth()->user()->events()->getQuery())
            ->actions([
                // works
                ViewAction::make(),
                // doesnt work
                Action::make('approveAction')
                    ->color('success')
                    ->requiresConfirmation()
                    ->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
                    ->action(fn (Events $record) => dd($record)),
                Action::make('rejectAction')
                    ->color('danger')
                    ->requiresConfirmation()
                    ->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
                    ->action(function (Events $record) {
                        $record->artists()->updateExistingPivot(Filament::auth()->user()->id, [
                            'invite_status' => ArtistInvite::REJECT
                        ]);
                    })
            ])
            ->columns( // columns from the trait EventListSchema
                $this->getEventTable()
            )
            ->contentGrid([
                'md' => 2,
            ]);
    }


Kindly help.
Was this page helpful?