F
Filament16mo ago
πTeR

How can I reuse slug update configurations?

return $form->schema([
TextInput::make('description')
->live()
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
}),
return $form->schema([
TextInput::make('description')
->live()
->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) {
if (($get('slug') ?? '') !== Str::slug($old)) {
return;
}

$set('slug', Str::slug($state));
}),
How can I reuse the callback on afterStateUpdated() between I my Forms? I have 4 Forms that uses slug and descriptions fields and I like to reuse it, because all was the same. Thanks
Solution:
Extract the callback? ```php public static function getSlugHandler() { return function (Get $get, Set $set, ?string $old, ?string $state) {...
Jump to solution
2 Replies
Solution
Patrick Boivin
Patrick Boivin16mo ago
Extract the callback?
public static function getSlugHandler()
{
return function (Get $get, Set $set, ?string $old, ?string $state) {
// ...
};
}

// ...

->afterStateUpdated(static::getSlugHandler())
public static function getSlugHandler()
{
return function (Get $get, Set $set, ?string $old, ?string $state) {
// ...
};
}

// ...

->afterStateUpdated(static::getSlugHandler())
πTeR
πTeROP16mo ago
Thank you
Want results from more Discord servers?
Add your server