Menggunakan Slug secara Otomatis di Laravel Filament
Postingan oleh.
Fadli
di kategori
Laravel Framework
pada
Forms\Components\TextInput::make('title') ->label('Judul') ->required() ->placeholder('Masukkan judul post') ->live(debounce: 500) ->afterStateUpdated(function (Get $get, Set $set, ?string $old, ?string $state) { if (($get('slug') ?? '') !== Str::slug($old)) { return; } $set('slug', Str::slug($state)); }), Forms\Components\TextInput::make('slug') ->label('Slug') ->required() ->placeholder('Masukkan slug post') ->unique(Post::class, 'slug', fn ($record) => $record),
public function setTitleAttribute($value) { $this->attributes['title'] = $value; $this->attributes['slug'] = Str::slug($value); }