From 3c289ef9e86606caa38c0c090bbb25904859f2b9 Mon Sep 17 00:00:00 2001 From: Thanh Trung Date: Fri, 1 Nov 2024 16:17:49 +0700 Subject: [PATCH] fix: adds validation unique for slug and key (#143) --- app/Filament/Resources/CategoryResource.php | 1 + app/Filament/Resources/FormsResource.php | 11 ++++++----- app/Filament/Resources/PageResource.php | 1 + app/Filament/Resources/PostResource.php | 1 + app/Filament/Resources/SettingResource.php | 1 + 5 files changed, 10 insertions(+), 5 deletions(-) diff --git a/app/Filament/Resources/CategoryResource.php b/app/Filament/Resources/CategoryResource.php index c0c7e3edd..9a9c3618c 100644 --- a/app/Filament/Resources/CategoryResource.php +++ b/app/Filament/Resources/CategoryResource.php @@ -30,6 +30,7 @@ public static function form(Form $form): Form ->maxLength(191), Forms\Components\TextInput::make('slug') ->required() + ->unique(ignoreRecord: true) ->maxLength(191), Forms\Components\Select::make('parent_id') ->label('Parent Category') diff --git a/app/Filament/Resources/FormsResource.php b/app/Filament/Resources/FormsResource.php index dee553fc1..1be5386ef 100644 --- a/app/Filament/Resources/FormsResource.php +++ b/app/Filament/Resources/FormsResource.php @@ -40,15 +40,16 @@ public static function form(Form $form): Form return $form ->schema([ TextInput::make('name') - ->label('Name') - ->required() - ->live(debounce: 500) - ->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))) - ->maxLength(191), + ->label('Name') + ->required() + ->live(debounce: 500) + ->afterStateUpdated(fn (Set $set, ?string $state) => $set('slug', Str::slug($state))) + ->maxLength(191), TextInput::make('slug') ->label('Slug') ->required() + ->unique(ignoreRecord: true) ->maxLength(191), Repeater::make('fields') diff --git a/app/Filament/Resources/PageResource.php b/app/Filament/Resources/PageResource.php index 822487ced..e6f0c2030 100644 --- a/app/Filament/Resources/PageResource.php +++ b/app/Filament/Resources/PageResource.php @@ -35,6 +35,7 @@ public static function form(Form $form): Form ->maxLength(191), Forms\Components\TextInput::make('slug') ->required() + ->unique(ignoreRecord: true) ->maxLength(191), Forms\Components\RichEditor::make('body') ->required() diff --git a/app/Filament/Resources/PostResource.php b/app/Filament/Resources/PostResource.php index 2171fa6f5..25df23536 100644 --- a/app/Filament/Resources/PostResource.php +++ b/app/Filament/Resources/PostResource.php @@ -36,6 +36,7 @@ public static function form(Form $form): Form ->maxLength(191), Forms\Components\TextInput::make('slug') ->required() + ->unique(ignoreRecord: true) ->maxLength(191), Forms\Components\RichEditor::make('body') ->required() diff --git a/app/Filament/Resources/SettingResource.php b/app/Filament/Resources/SettingResource.php index d9b47c1f5..b205b7846 100644 --- a/app/Filament/Resources/SettingResource.php +++ b/app/Filament/Resources/SettingResource.php @@ -27,6 +27,7 @@ public static function form(Form $form): Form ->schema([ Forms\Components\TextInput::make('key') ->required() + ->unique(ignoreRecord: true) ->maxLength(191), Forms\Components\TextInput::make('display_name') ->required()