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(),
                        ]);
                    })
Was this page helpful?