From 0451732f0f6101654a1bb91b83821b415459edd3 Mon Sep 17 00:00:00 2001 From: Ash Monsh Date: Thu, 22 Jun 2023 20:08:21 +0300 Subject: [PATCH 1/2] add categories to FAQ --- config/zeus-sky.php | 1 + resources/lang/ar.json | 3 ++- .../filament/columns/tag-counts.blade.php | 3 +++ src/Filament/Resources/FaqResource.php | 18 ++++++++++++++++++ src/Filament/Resources/TagResource.php | 4 +++- src/Models/Faq.php | 2 ++ src/Models/Tag.php | 12 ++++++++++++ 7 files changed, 41 insertions(+), 2 deletions(-) create mode 100644 resources/views/filament/columns/tag-counts.blade.php diff --git a/config/zeus-sky.php b/config/zeus-sky.php index 3b94027..7d4bb09 100644 --- a/config/zeus-sky.php +++ b/config/zeus-sky.php @@ -123,6 +123,7 @@ 'tag' => 'Tag', 'category' => 'Category', 'library' => 'Library', + 'faq' => 'faq', ], /** diff --git a/resources/lang/ar.json b/resources/lang/ar.json index 8cf237b..b98ca94 100644 --- a/resources/lang/ar.json +++ b/resources/lang/ar.json @@ -77,5 +77,6 @@ "Library File": "ملف المكتبة", "file url": "رابط الملف", "Send": "ارسال", - "sorry, the password incorrect!": "عفوا، كلمة المرور غير صحيحة" + "sorry, the password incorrect!": "عفوا، كلمة المرور غير صحيحة", + "FAQ Categories": "التصنيفات" } diff --git a/resources/views/filament/columns/tag-counts.blade.php b/resources/views/filament/columns/tag-counts.blade.php new file mode 100644 index 0000000..70af7c9 --- /dev/null +++ b/resources/views/filament/columns/tag-counts.blade.php @@ -0,0 +1,3 @@ +
+ {{ $getRecord()->{$getRecord()->type}()->count() }} +
\ No newline at end of file diff --git a/src/Filament/Resources/FaqResource.php b/src/Filament/Resources/FaqResource.php index c9396be..4bc5707 100644 --- a/src/Filament/Resources/FaqResource.php +++ b/src/Filament/Resources/FaqResource.php @@ -3,13 +3,16 @@ namespace LaraZeus\Sky\Filament\Resources; use Filament\Forms\Components\RichEditor; +use Filament\Forms\Components\SpatieTagsInput; use Filament\Forms\Components\Textarea; use Filament\Resources\Form; use Filament\Resources\Table; use Filament\Tables\Actions\ActionGroup; use Filament\Tables\Actions\DeleteAction; use Filament\Tables\Actions\EditAction; +use Filament\Tables\Columns\SpatieTagsColumn; use Filament\Tables\Columns\TextColumn; +use Filament\Tables\Filters\SelectFilter; use LaraZeus\Sky\Filament\Resources\FaqResource\Pages; use LaraZeus\Sky\Models\Faq; @@ -57,6 +60,10 @@ public static function form(Form $form): Form ->required() ->maxLength(65535) ->columnSpan(2), + + SpatieTagsInput::make('category') + ->type('faq') + ->label(__('FAQ Categories')), ]); } @@ -65,6 +72,17 @@ public static function table(Table $table): Table return $table ->columns([ TextColumn::make('question')->searchable(), + + SpatieTagsColumn::make('tags') + ->label(__('FAQ Categories')) + ->toggleable() + ->type('faq'), + ]) + ->filters([ + SelectFilter::make('tags') + ->multiple() + ->relationship('tags', 'name') + ->label(__('Tags')), ]) ->actions([ ActionGroup::make([ diff --git a/src/Filament/Resources/TagResource.php b/src/Filament/Resources/TagResource.php index 1512cc3..114df45 100644 --- a/src/Filament/Resources/TagResource.php +++ b/src/Filament/Resources/TagResource.php @@ -62,7 +62,9 @@ public static function table(Table $table): Table TextColumn::make('name')->toggleable()->searchable()->sortable(), TextColumn::make('type')->toggleable()->searchable()->sortable(), TextColumn::make('slug')->toggleable()->searchable()->sortable(), - TextColumn::make('posts_count')->counts('posts')->toggleable()->searchable()->sortable(), + TextColumn::make('items_count') + ->toggleable() + ->view('zeus-sky::filament.columns.tag-counts'), ]) ->filters([ SelectFilter::make('type') diff --git a/src/Models/Faq.php b/src/Models/Faq.php index 0b6a8ae..30eab4a 100644 --- a/src/Models/Faq.php +++ b/src/Models/Faq.php @@ -3,11 +3,13 @@ namespace LaraZeus\Sky\Models; use Illuminate\Database\Eloquent\Model; +use Spatie\Tags\HasTags; use Spatie\Translatable\HasTranslations; class Faq extends Model { use HasTranslations; + use HasTags; public $translatable = [ 'question', diff --git a/src/Models/Tag.php b/src/Models/Tag.php index 982b357..813bec9 100644 --- a/src/Models/Tag.php +++ b/src/Models/Tag.php @@ -19,6 +19,18 @@ public function library() return $this->morphedByMany(config('zeus-sky.models.library'), 'taggable'); } + public function category() + { + return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable'); + } + + public function faq() + { + return $this->morphedByMany(config('zeus-sky.models.faq'), 'taggable'); + } + + + public function postsPublished() { return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable')->published(); From 9af73ece47b2f48f4004d2cab9981b6e4dd41e16 Mon Sep 17 00:00:00 2001 From: atmonshi Date: Thu, 22 Jun 2023 17:08:47 +0000 Subject: [PATCH 2/2] Fix styling --- src/Models/Tag.php | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/Models/Tag.php b/src/Models/Tag.php index 813bec9..e00e8f7 100644 --- a/src/Models/Tag.php +++ b/src/Models/Tag.php @@ -29,8 +29,6 @@ public function faq() return $this->morphedByMany(config('zeus-sky.models.faq'), 'taggable'); } - - public function postsPublished() { return $this->morphedByMany(config('zeus-sky.models.post'), 'taggable')->published();