Generate slugs from a title whilst typing (without overriding)

Jun 8, 2022
Ralph J. Smit
Form builder

Sometimes you want your users to input a title (e.g. for a blog post) and automatically generate a slug from that title. However, you want to stop overriding the slug when the user has made at least one manual change.

Luckily, this is quite easy to achieve with a hidden field, to store an addition value:

->afterStateUpdated(function (Closure $get, Closure $set, ?string $state) {
if (! $get('is_slug_changed_manually') && filled($state)) {
$set('slug', Str::slug($state));
->afterStateUpdated(function (Closure $set) {
$set('is_slug_changed_manually', true);

I have created a filament plugin to help you enter titles & slugs, which includes the feature described above.

"Title with Slug" Input - Simple Permalink Slugs for Filament Forms

Simply add the Field to your Filament form, and all title and slug related editing functions are available.

fieldTitle: 'title',
fieldSlug: 'slug',

Best, Andreas