How to trigger an action from a TextColumn

Hello, how can we trigger an action from a table column? Here's my text column
Tables\Columns\TextColumn::make('status')
->translateLabel()
->badge()
->color(fn ($state) => $state->getColor())
->toggleable()
->sortable()
->searchable()->forceSearchCaseInsensitive()
->suffix(function ($state) {
if ($state === Enums\ReservationStatus::READY) {
return ' ('.__('Add booking review').')';
}
})
->action(function (Reservation $record, Table $table) {
info(1);
// how to trigger writeReview action
}),
Tables\Columns\TextColumn::make('status')
->translateLabel()
->badge()
->color(fn ($state) => $state->getColor())
->toggleable()
->sortable()
->searchable()->forceSearchCaseInsensitive()
->suffix(function ($state) {
if ($state === Enums\ReservationStatus::READY) {
return ' ('.__('Add booking review').')';
}
})
->action(function (Reservation $record, Table $table) {
info(1);
// how to trigger writeReview action
}),
And this is my action that I want to trigger
Tables\Actions\Action::make('writeReview')
->label(__('Booking review'))
->form([
Forms\Components\TextInput::make('review.rating')
->translateLabel()
->minValue(1)
->maxValue(10)
->step(1)
->numeric()
->required()
->default(fn ($record) => $record->review?->rating),
Forms\Components\Textarea::make('review.comment')
->translateLabel()
->default(fn ($record) => $record->review?->comment)
->helperText(fn ($record) => __(':name review', ['name' => $record->client?->name])),
])
->action(function (array $data, Reservation $record): void {
$record->review()->updateOrCreate([], $data['review']);
})
->hidden(true),
Tables\Actions\Action::make('writeReview')
->label(__('Booking review'))
->form([
Forms\Components\TextInput::make('review.rating')
->translateLabel()
->minValue(1)
->maxValue(10)
->step(1)
->numeric()
->required()
->default(fn ($record) => $record->review?->rating),
Forms\Components\Textarea::make('review.comment')
->translateLabel()
->default(fn ($record) => $record->review?->comment)
->helperText(fn ($record) => __(':name review', ['name' => $record->client?->name])),
])
->action(function (array $data, Reservation $record): void {
$record->review()->updateOrCreate([], $data['review']);
})
->hidden(true),
Solution:
Found the answer ```php ->action(function (Reservation $record, $livewire) { $livewire->mountTableAction('writeReview', $record->id); }...
Jump to solution
2 Replies
Jellibloom
JellibloomOP8mo ago
I've tried this, but not working $table->getAction('writeReview');
Solution
Jellibloom
Jellibloom8mo ago
Found the answer
->action(function (Reservation $record, $livewire) {
$livewire->mountTableAction('writeReview', $record->id);
}
->action(function (Reservation $record, $livewire) {
$livewire->mountTableAction('writeReview', $record->id);
}
Want results from more Discord servers?
Add your server