Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add categories to FAQ #112

Merged
merged 2 commits into from
Jun 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/zeus-sky.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,7 @@
'tag' => 'Tag',
'category' => 'Category',
'library' => 'Library',
'faq' => 'faq',
],

/**
Expand Down
3 changes: 2 additions & 1 deletion resources/lang/ar.json
Original file line number Diff line number Diff line change
Expand Up @@ -77,5 +77,6 @@
"Library File": "ملف المكتبة",
"file url": "رابط الملف",
"Send": "ارسال",
"sorry, the password incorrect!": "عفوا، كلمة المرور غير صحيحة"
"sorry, the password incorrect!": "عفوا، كلمة المرور غير صحيحة",
"FAQ Categories": "التصنيفات"
}
3 changes: 3 additions & 0 deletions resources/views/filament/columns/tag-counts.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<div>
{{ $getRecord()->{$getRecord()->type}()->count() }}
</div>
18 changes: 18 additions & 0 deletions src/Filament/Resources/FaqResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -57,6 +60,10 @@ public static function form(Form $form): Form
->required()
->maxLength(65535)
->columnSpan(2),

SpatieTagsInput::make('category')
->type('faq')
->label(__('FAQ Categories')),
]);
}

Expand All @@ -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([
Expand Down
4 changes: 3 additions & 1 deletion src/Filament/Resources/TagResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 2 additions & 0 deletions src/Models/Faq.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
10 changes: 10 additions & 0 deletions src/Models/Tag.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,16 @@ 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();
Expand Down