F
Filament2mo ago
Tii

Preset attributes according to selected tab/previously created record

I have an Event resource. I display it with tabs filtered for a type, like one tab for type "A", one for type "B" etc. When you click on Create on the top right it should prefill the new record with the type that was previously selected as tab. I achieved this by overwriting this method:
protected function getHeaderActions(): array
{
return [
CreateAction::make()
->url(fn () => route('filament.admin.resources.calendar.events.create', [
'type' => $this->activeTab,
])),
];
}
protected function getHeaderActions(): array
{
return [
CreateAction::make()
->url(fn () => route('filament.admin.resources.calendar.events.create', [
'type' => $this->activeTab,
])),
];
}
When you click on "Create and create another" it should stay that way and in addition to this I'd like to set the start_time of the next record to one week after the one that was just created. I'm not sure how to achieve this. I'm also not sure if there is a better way for the CreateAction.
1 Reply
Tii
TiiOP2mo ago
I added a afterCreate function like this:
protected function afterCreate(): void
{
Session::flash('event', $this->record);
}
protected function afterCreate(): void
{
Session::flash('event', $this->record);
}
After that I could use the session helper function to get my event from the previous creation. That works for the first request after creation like with "create another" but ideally those data would persist with a reload. But only when you click on "create another". If I would switch to Session::put(...) it would be saved for too long, since it would be prefilled even if you abort the creation and come back to it later in that session. Any improvement proposals? I'm happy for every hint.
Want results from more Discord servers?
Add your server