Customizing data before saving
On my BD I have:
On my form, I have:
In my model, I have:
I want when the toggle is used the 'marked_ready_at' to automatically grab the current date/time.
I have tried the following:
On my Pages/Edit
What I/m doing wrong?
Is there a better approach?
Thanks.
6 Replies
You try “afterStateUpdated” for Toggle ?
Hidden::make(“marked_ready_at”), Toggle::make(“is_ready”)->afterStateUpdated(function($set, $state) :void {if($state}{$set(“marked_ready_at, now())});
and Hi,
thank you for your time... I have done:
Works, but...
I want the date time to be grabbed when the user saves the record.
Like this, the time and date recorded is the one when the toggle was used.
You can add an observer for model
And for created event set marked_ready_at
Thanks...
I'll look at that, just one question if you have the time, please.
The "mutateFormDataBeforeSave" approach you consider not good for the case?
Thanks.
https://filamentphp.com/docs/2.x/admin/resources/editing-records#customizing-data-before-saving
Filament
Editing records - Resources - Admin Panel - Filament
The elegant TALL stack admin panel for Laravel artisans.
If in method you change condition for if, ex: if($data[‘is_ready’] ?? false) {your code} not working ?
Thank you...
I think I had my code wrong...
By default "is_ready" is false.
So, I have to check if it is false:
"if ( ! $this->record->is_ready) ..."
not:
"if ( $this->record->is_ready) ..."
Thanks for your time.