© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
FilamentF
Filament•3y ago•
20 replies
David | Fortune Validator

Get data in ->after() on a custom action

I have the following code. I would like to get the newly created record to use as a redirect in the ->after() function. If any one could help I would appreciate it. Also if I am doing this a long way please let me know.

Action::make('Log Today')
                    ->button()
                    ->action(function (Action $action){
                        $tenantId = Filament::getTenant()->id;
                        $today = date('Y-m-d');
                        $day = Day::firstOrCreate(
                            ['date' => $today, 'person_id' => $tenantId],
                            ['date' => now()]
                        );
                    })
                    ->after(function () {
                        Notification::make()
                            ->success()
                            ->title('Day Record Created!')
                            ->send();

                        return redirect()->route('filament.app.resources.days.view',[
                            'tenant' => Filament::getTenant(),
                            'record' => Day::where('date',date('Y-m-d'))->where('person_id',Filament::getTenant()->id)->first(),
                        ]);
                    })
Action::make('Log Today')
                    ->button()
                    ->action(function (Action $action){
                        $tenantId = Filament::getTenant()->id;
                        $today = date('Y-m-d');
                        $day = Day::firstOrCreate(
                            ['date' => $today, 'person_id' => $tenantId],
                            ['date' => now()]
                        );
                    })
                    ->after(function () {
                        Notification::make()
                            ->success()
                            ->title('Day Record Created!')
                            ->send();

                        return redirect()->route('filament.app.resources.days.view',[
                            'tenant' => Filament::getTenant(),
                            'record' => Day::where('date',date('Y-m-d'))->where('person_id',Filament::getTenant()->id)->first(),
                        ]);
                    })
Filament banner
FilamentJoin
A powerful open source UI framework for Laravel • Build and ship admin panels & apps fast with Livewire
20,307Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

Loosing data after clicking on custom action.
FilamentFFilament / ❓┊help
3y ago
Retrieve data from a custom Filament\Actions\Action
FilamentFFilament / ❓┊help
12mo ago
How to insert data in a custom action
FilamentFFilament / ❓┊help
2y ago
Redirect after custom action
FilamentFFilament / ❓┊help
2y ago