FilamentF
Filament2y ago
🍠

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
  }),


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),
Solution
Found the answer
->action(function (Reservation $record, $livewire) {
      $livewire->mountTableAction('writeReview', $record->id);
}
Was this page helpful?