More macros
New macros
Change the state of the current field
- loadAs => afterStateHydrated
- saveAs => dehydrateStateUsing
- updateAs => afterStateUpdated
Any callback
- onLoaded => afterStateHydrated
- onSave => dehydrateStateUsing
- onUpdated => afterStateUpdated
loadAs, saveAs, updateAs
Changes the state of the current field
Example
//Instead of this
TextInput::make('name')
->afterStateHydrated(function (TextInput $component, $state) {
$component->state(ucwords($state));
})
//use the macro
TextInput::make('name')->loadAs(fn ($state) => ucwords($state))
onLoaded, onSave, onUpdated
Just a way to be more clear on the lifecycle. I never remember the Filament naming or what it means.
I use it when I want to change the state of another field.
Example
TextInput::make('slug')
//Instead of this
TextInput::make('title')
->reactive()
->afterStateUpdated(function ($set, $state) {
$set('slug', \Str::slug($state));
})
//use the macro to be more clear about the lifecycle stage
TextInput::make('title')
->reactive()
->onUpdated(fn ($set, $state) => $set('slug', \Str::slug($state)))