From b5c591babb8b5d086269b6146dda2c018c0b0bcc Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Wed, 2 Nov 2022 09:21:57 +0100 Subject: [PATCH 1/3] add unique() constraint to slug fields --- src/Filament/Resources/PageResource.php | 1 + src/Filament/Resources/PostResource.php | 1 + src/Filament/Resources/TagResource.php | 1 + 3 files changed, 3 insertions(+) diff --git a/src/Filament/Resources/PageResource.php b/src/Filament/Resources/PageResource.php index 47413e9..9d0f81e 100644 --- a/src/Filament/Resources/PageResource.php +++ b/src/Filament/Resources/PageResource.php @@ -77,6 +77,7 @@ public static function form(Form $form): Form ->hint(__('Write an excerpt for your post')), TextInput::make('slug') + ->unique() ->required() ->maxLength(255) ->label(__('Post Slug')), diff --git a/src/Filament/Resources/PostResource.php b/src/Filament/Resources/PostResource.php index 7027724..87b8480 100644 --- a/src/Filament/Resources/PostResource.php +++ b/src/Filament/Resources/PostResource.php @@ -77,6 +77,7 @@ public static function form(Form $form): Form ->hint(__('Write an excerpt for your post')), TextInput::make('slug') + ->unique() ->required() ->maxLength(255) ->label(__('Post Slug')), diff --git a/src/Filament/Resources/TagResource.php b/src/Filament/Resources/TagResource.php index 5dbfc02..00a38cf 100644 --- a/src/Filament/Resources/TagResource.php +++ b/src/Filament/Resources/TagResource.php @@ -43,6 +43,7 @@ public static function form(Form $form): Form $set('slug', Str::slug($state)); }), TextInput::make('slug') + ->unique() ->required() ->maxLength(255), Select::make('type') From 546a69778c56ca57a041fb1f1328f5600dec9ae3 Mon Sep 17 00:00:00 2001 From: Herbert Maschke Date: Mon, 7 Nov 2022 10:52:10 +0100 Subject: [PATCH 2/3] add :ignorable to unique() contraints --- src/Filament/Resources/PageResource.php | 3 ++- src/Filament/Resources/PostResource.php | 3 ++- src/Filament/Resources/TagResource.php | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/Filament/Resources/PageResource.php b/src/Filament/Resources/PageResource.php index 9d0f81e..64f66d6 100644 --- a/src/Filament/Resources/PageResource.php +++ b/src/Filament/Resources/PageResource.php @@ -19,6 +19,7 @@ use Filament\Tables\Filters\MultiSelectFilter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Str; +use Illuminate\Database\Eloquent\Model; use LaraZeus\Sky\Filament\Resources\PageResource\Pages; use LaraZeus\Sky\Models\Post; use LaraZeus\Sky\Models\PostStatus; @@ -77,7 +78,7 @@ public static function form(Form $form): Form ->hint(__('Write an excerpt for your post')), TextInput::make('slug') - ->unique() + ->unique(ignorable: fn (?Model $record): ?Model => $record) ->required() ->maxLength(255) ->label(__('Post Slug')), diff --git a/src/Filament/Resources/PostResource.php b/src/Filament/Resources/PostResource.php index 87b8480..abc6734 100644 --- a/src/Filament/Resources/PostResource.php +++ b/src/Filament/Resources/PostResource.php @@ -21,6 +21,7 @@ use Filament\Tables\Filters\MultiSelectFilter; use Illuminate\Database\Eloquent\Builder; use Illuminate\Support\Str; +use Illuminate\Database\Eloquent\Model; use LaraZeus\Sky\Filament\Resources\PostResource\Pages; use LaraZeus\Sky\Models\Post; use LaraZeus\Sky\Models\PostStatus; @@ -77,7 +78,7 @@ public static function form(Form $form): Form ->hint(__('Write an excerpt for your post')), TextInput::make('slug') - ->unique() + ->unique(ignorable: fn (?Model $record): ?Model => $record) ->required() ->maxLength(255) ->label(__('Post Slug')), diff --git a/src/Filament/Resources/TagResource.php b/src/Filament/Resources/TagResource.php index 00a38cf..700b71a 100644 --- a/src/Filament/Resources/TagResource.php +++ b/src/Filament/Resources/TagResource.php @@ -9,6 +9,7 @@ use Filament\Resources\Table; use Filament\Tables\Columns\TextColumn; use Illuminate\Support\Str; +use Illuminate\Database\Eloquent\Model; use LaraZeus\Sky\Filament\Resources\TagResource\Pages; use LaraZeus\Sky\Models\Tag; @@ -43,7 +44,7 @@ public static function form(Form $form): Form $set('slug', Str::slug($state)); }), TextInput::make('slug') - ->unique() + ->unique(ignorable: fn (?Model $record): ?Model => $record) ->required() ->maxLength(255), Select::make('type') From a79eeac0a61eec6ca1235e3b10745d504ce4a470 Mon Sep 17 00:00:00 2001 From: thyseus Date: Mon, 7 Nov 2022 09:53:16 +0000 Subject: [PATCH 3/3] Fix styling --- src/Filament/Resources/PageResource.php | 2 +- src/Filament/Resources/PostResource.php | 2 +- src/Filament/Resources/TagResource.php | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Filament/Resources/PageResource.php b/src/Filament/Resources/PageResource.php index 64f66d6..f0b7643 100644 --- a/src/Filament/Resources/PageResource.php +++ b/src/Filament/Resources/PageResource.php @@ -18,8 +18,8 @@ use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\MultiSelectFilter; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; use LaraZeus\Sky\Filament\Resources\PageResource\Pages; use LaraZeus\Sky\Models\Post; use LaraZeus\Sky\Models\PostStatus; diff --git a/src/Filament/Resources/PostResource.php b/src/Filament/Resources/PostResource.php index abc6734..a1bc0f2 100644 --- a/src/Filament/Resources/PostResource.php +++ b/src/Filament/Resources/PostResource.php @@ -20,8 +20,8 @@ use Filament\Tables\Filters\Filter; use Filament\Tables\Filters\MultiSelectFilter; use Illuminate\Database\Eloquent\Builder; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; use LaraZeus\Sky\Filament\Resources\PostResource\Pages; use LaraZeus\Sky\Models\Post; use LaraZeus\Sky\Models\PostStatus; diff --git a/src/Filament/Resources/TagResource.php b/src/Filament/Resources/TagResource.php index 700b71a..ed74d23 100644 --- a/src/Filament/Resources/TagResource.php +++ b/src/Filament/Resources/TagResource.php @@ -8,8 +8,8 @@ use Filament\Resources\Form; use Filament\Resources\Table; use Filament\Tables\Columns\TextColumn; -use Illuminate\Support\Str; use Illuminate\Database\Eloquent\Model; +use Illuminate\Support\Str; use LaraZeus\Sky\Filament\Resources\TagResource\Pages; use LaraZeus\Sky\Models\Tag;