Skip to content

novius/laravel-filament-slug

Repository files navigation

Laravel Filament Slug

Novius CI Packagist Release License: AGPL v3

Introduction

This package add a Slug field to Filament Forms

Requirements

  • PHP >= 8.2
  • Laravel >= 11.0
  • Laravel Filament >= 3.3

Installation

composer require novius/laravel-filament-slug

Usage

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
                    ),
            ]);
    }
}

Lint

Run php-cs with:

composer run-script lint

Contributing

Contributions are welcome!

Leave an issue on GitHub, or create a Pull Request.

Licence

This package is under GNU Affero General Public License v3 or (at your option) any later version.

About

A Laravel Filament slug form field

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages