F
Filament11mo ago
toeknee

Action not trigging in a livewire component?

Simple action:
public function saveAndResumeAction(): Action
{
return Action::make('save_resume')
->label('Save and Resume Later')
->form([
TextInput::make('test')->label('Test'),
])
->action(fn () => dd('hit')
);
}
public function saveAndResumeAction(): Action
{
return Action::make('save_resume')
->label('Save and Resume Later')
->form([
TextInput::make('test')->label('Test'),
])
->action(fn () => dd('hit')
);
}
called with this in the view:
{{ $this->saveAndResumeAction }}
<x-filament-actions::modals />
{{ $this->saveAndResumeAction }}
<x-filament-actions::modals />
Just spins and doesn't do anything and action is never hit... suggestions? if I write a function
public function save_resume()
{
dd('hit me');
}
public function save_resume()
{
dd('hit me');
}
then save_resume function is hit...
Solution:
Resolved, the action need to have the same naming convention less Action in the name of the action.
Jump to solution
10 Replies
Solution
toeknee
toeknee11mo ago
Resolved, the action need to have the same naming convention less Action in the name of the action.
Matthew
Matthew11mo ago
Yeah, the docs dont explain this well enough 😅 I had a similar issue a couple of months ago
toeknee
toekneeOP11mo ago
Ahhh! I’ll do a PR soon
Anik
Anik10mo ago
I am having a similar issue with table Action. Can you please explain the solution?
toeknee
toekneeOP10mo ago
Provide your code please
Anik
Anik10mo ago
public function table(Table $table): Table
{
return $table
->actions([

Action::make('approveAction')
->color('success')
->requiresConfirmation()
->action(fn (Events $record) => dd($record)),
Action::make('reject')
->color('danger')
->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
->action(function (?Model $record) {
$record->artists()->updateExistingPivot(Filament::auth()->user()->id, [
'state' => ArtistInvite::REJECT
]);
})
])
->columns( // columns from the trait EventListSchema
$this->getEventTable()
)
->contentGrid([
'md' => 2,
]);
}
public function table(Table $table): Table
{
return $table
->actions([

Action::make('approveAction')
->color('success')
->requiresConfirmation()
->action(fn (Events $record) => dd($record)),
Action::make('reject')
->color('danger')
->visible(fn (Events $record): bool => $record->invite_status == ArtistInvite::SENT)
->action(function (?Model $record) {
$record->artists()->updateExistingPivot(Filament::auth()->user()->id, [
'state' => ArtistInvite::REJECT
]);
})
])
->columns( // columns from the trait EventListSchema
$this->getEventTable()
)
->contentGrid([
'md' => 2,
]);
}
The approveAction is not triggering. The page extends a list record page. Filament v3.2.14 imported class
use Filament\Tables\Actions\Action;
use Filament\Tables\Actions\Action;
even the confirmation modal is not opened but i see a network request to livewire/update The action was not working because of this query()
// ->query(fn (): Builder => Filament::auth()->user()->events()->getQuery())
// ->query(fn (): Builder => Filament::auth()->user()->events()->getQuery())
updating query to below works for action but I loose the pivot classes for the many to many relation. Kindly help
->query(fn (): Builder => Events::whereHas('artists', function ($query) {
$query->where('artists.id', Filament::auth()->user()->id);
}))
->query(fn (): Builder => Events::whereHas('artists', function ($query) {
$query->where('artists.id', Filament::auth()->user()->id);
}))
Matthew
Matthew10mo ago
your reject function should be names "rejectAction"
Anik
Anik10mo ago
the approveAction doesn't work friend its because of the query this has been the case. i cannot get Action to work with relationship getQuery
public function table(Table $table): Table
{
return $table
// action works but pivot data is not loaded
// ->query(fn (): Builder => Events::whereHas('artists', function ($query) {
// $query->where('artists.id', Filament::auth()->user()->id);
// }))
// pivot data is loaded but Action dont trigger
->query(fn (): Builder => Filament::auth()->user()->events()->getQuery())
->actions([

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,
]);
}
public function table(Table $table): Table
{
return $table
// action works but pivot data is not loaded
// ->query(fn (): Builder => Events::whereHas('artists', function ($query) {
// $query->where('artists.id', Filament::auth()->user()->id);
// }))
// pivot data is loaded but Action dont trigger
->query(fn (): Builder => Filament::auth()->user()->events()->getQuery())
->actions([

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,
]);
}
toeknee
toekneeOP10mo ago
Unfortunately I am not familiar using it with pivots too
Anik
Anik10mo ago
got it solved with
->action(fn(?Model $record) => dd($record)),
->action(fn(?Model $record) => dd($record)),
Want results from more Discord servers?
Add your server