0

I have actions like this in a resource (replicate and edit):

public static function table(Table $table): Table
{
    return $table
        ->columns([
            Tables\Columns\TextColumn::make('base_currency.name')->sortable(),
            Tables\Columns\TextColumn::make('target_currency.name')->sortable(),
            Tables\Columns\TextColumn::make('rate'),
            Tables\Columns\TextColumn::make('created_at')->dateTime()->sortable(),
            Tables\Columns\IconColumn::make('is_current')
                ->boolean()
                ->trueIcon('heroicon-o-badge-check')
                ->falseIcon('heroicon-o-x-circle'),
        ])
        ->defaultSort('created_at', 'desc')
        ->filters([
            Tables\Filters\SelectFilter::make('base_currency_id')
                ->options(Currency::getAll()->mapWithKeys(function ($currency, $key) {
                    return [$currency->id => $currency->code];
                }))
                ->label('Base currency'),
            Tables\Filters\SelectFilter::make('target_currency_id')
                ->options(Currency::getAll()->mapWithKeys(function ($currency, $key) {
                    return [$currency->id => $currency->code];
                }))
                ->label('Target currency'),
            Tables\Filters\Filter::make('is_current')
                ->query(fn(Builder $query): Builder => $query->where('is_current', true))
                ->label('Current only')
                ->default(),
        ])
        ->actions([
            Tables\Actions\ReplicateAction::make('replicate')
                ->beforeReplicaSaved(
                    function (Model $replica): void {
                        $replica->is_current = true;
                        ExchangeRate::query()->where([
                            'base_currency_id' => $replica->base_currency_id,
                            'target_currency_id' => $replica->target_currency_id,
                            'is_current' => true,
                        ])
                            ->update(['is_current' => false]);
                    }
                )
                ->after(fn (Model $record) => route('exchange-rates.edit', $record)),
            Tables\Actions\EditAction::make(),
        ])
        ->bulkActions([
            Tables\Actions\DeleteBulkAction::make(),
        ]);
}

It is necessary in after to make it so that after replicate the record, the transition to the page with editing is carried out, similar to the EditAction action, how to do this?

after(fn (Model $record) => route('exchange-rates.edit', $record))

This doesn't work because no registered route

1 Answers1

0

If you want to redirect any action you need to add redirection code in the ->action()

Tables\Actions\Action::make('Go to Edit')
    ->color('success')
    ->icon('heroicon-o-link')
    ->action(fn (Model $record) => redirect()->route('filament.resources.todos.edit', $record)),

and you already know how to check the route list in the laravel.

php artisan route:list

enter image description here

Hope it will help.

and yes, please check out my Filament Package for a custom action, Filament Action.

Happy coding!...

Mitesh Rathod
  • 879
  • 5
  • 18