Skip to content

Commit

Permalink
Merge pull request #57 from amvisor/slug-unique
Browse files Browse the repository at this point in the history
add unique() constraint to slug fields
  • Loading branch information
atmonshi authored Nov 7, 2022
2 parents 2c375d8 + a79eeac commit 7ac43b8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Filament/Resources/PageResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\MultiSelectFilter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use LaraZeus\Sky\Filament\Resources\PageResource\Pages;
use LaraZeus\Sky\Models\Post;
Expand Down Expand Up @@ -77,6 +78,7 @@ public static function form(Form $form): Form
->hint(__('Write an excerpt for your post')),

TextInput::make('slug')
->unique(ignorable: fn (?Model $record): ?Model => $record)
->required()
->maxLength(255)
->label(__('Post Slug')),
Expand Down
2 changes: 2 additions & 0 deletions src/Filament/Resources/PostResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
use Filament\Tables\Filters\Filter;
use Filament\Tables\Filters\MultiSelectFilter;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use LaraZeus\Sky\Filament\Resources\PostResource\Pages;
use LaraZeus\Sky\Models\Post;
Expand Down Expand Up @@ -77,6 +78,7 @@ public static function form(Form $form): Form
->hint(__('Write an excerpt for your post')),

TextInput::make('slug')
->unique(ignorable: fn (?Model $record): ?Model => $record)
->required()
->maxLength(255)
->label(__('Post Slug')),
Expand Down
2 changes: 2 additions & 0 deletions src/Filament/Resources/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use Filament\Resources\Form;
use Filament\Resources\Table;
use Filament\Tables\Columns\TextColumn;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Str;
use LaraZeus\Sky\Filament\Resources\TagResource\Pages;
use LaraZeus\Sky\Models\Tag;
Expand Down Expand Up @@ -43,6 +44,7 @@ public static function form(Form $form): Form
$set('slug', Str::slug($state));
}),
TextInput::make('slug')
->unique(ignorable: fn (?Model $record): ?Model => $record)
->required()
->maxLength(255),
Select::make('type')
Expand Down

0 comments on commit 7ac43b8

Please sign in to comment.