This package add a Slug field to Filament Forms
- PHP >= 8.2
- Laravel >= 11.0
- Laravel Filament >= 3.3
composer require novius/laravel-filament-slug
class YourResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
$title = TextInput::make('title')
->required(),
Slug::make('slug')
// First parameter of fromField() must be the TextInput instance from which the slug is generated.
// Second parameter is optional. If passed, must be a closure returning if the slug generation should be skip or not.
->fromField($title, fn (Get $get) => ! $get('other_value'))
// Slug inherit from TextInput. You can use all other method of TextInput.
->required()
->string()
->regex('/^(\/|[a-zA-Z0-9-_]+)$/')
->unique(
YourModel::class,
'slug',
ignoreRecord: true
),
]);
}
}
Run php-cs with:
composer run-script lint
Contributions are welcome!
Leave an issue on GitHub, or create a Pull Request.
This package is under GNU Affero General Public License v3 or (at your option) any later version.