- How do I add a Slug field to a Filament resource form?
- Use `Slug::make('slug')->fromField($title)` in your resource’s `form()` method, where `$title` is the TextInput instance. The slug will auto-generate from the title field. Add validation rules like `required()`, `unique()`, or `regex()` just like a TextInput.
- Can I conditionally skip slug generation?
- Yes. Pass a closure to `fromField()` as the second argument (e.g., `->fromField($title, fn(Get $get) => !$get('is_published'))`). This skips slug generation if the condition returns true, such as for unpublished drafts.
- Does this package work with Laravel 10 or Filament 3?
- No. This package requires **Laravel 11+** and **Filament 4+**. It leverages Filament’s form API, which changed significantly in Filament 4, so older versions are unsupported.
- How do I handle duplicate slugs (e.g., auto-increment suffixes like `/post-2`)?
- The package doesn’t include built-in collision handling. Use Laravel’s `Str::slug()` with custom logic (e.g., a database constraint or observer) or override the `generate()` method to append suffixes manually.
- Will this work with multilingual content (e.g., non-English characters)?
- By default, it uses PHP’s `Str::slug()`, which may not handle multilingual characters optimally. For custom formats (e.g., underscores), override the `generate()` method or use a third-party slug library like `spatie/laravel-sluggable`.
- Can I use this in Filament Pages (not just Resources)?
- Yes. The Slug field works anywhere Filament forms are used, including Pages. Just include it in the `form()` method schema, just like in Resources. Example: `Slug::make('slug')->fromField($name)`.
- Does this package support bulk slug generation in Filament tables?
- Yes, but with limitations. Slugs generated via `fromField()` won’t auto-update in bulk actions (e.g., `update()`). For bulk operations, use Filament’s `afterStateUpdated` or handle slugs in a custom table action.
- How do I test slug generation in my Laravel tests?
- Mock the `fromField()` closure or use `partialMock()` to test slug generation logic. For validation, test with `->assertHasNoFormErrors()` or `->assertHasFormErrors()`. Example: `$form->fill(['title' => 'Test Post'])->assertSet('slug', 'test-post').`
- Is there a performance impact for real-time slug generation?
- Yes, real-time generation triggers validation and potential database queries (e.g., `unique()` checks). For better performance, use `live(false)` or defer generation with `afterStateUpdated()` to batch slug creation.
- What are the alternatives to this package?
- For Filament, consider `spatie/laravel-sluggable` (model-level slugs) or `filament/spatie-laravel-sluggable` (Filament integration). For custom solutions, use `Str::slug()` in observers or accessors. However, this package is the only dedicated Filament Slug form field.