Skip to content

AfeaSoftware/filament-faq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

afea/filament-faq

FAQ module for the Afea Filament CMS package ecosystem.

Ships:

  • Faq and FaqCategory models
  • HasFaqs trait — add to any model to attach FAQs polymorphically through the faqables pivot (carries order so each host orders its FAQs independently)
  • FaqResource, FaqCategoryResource (Filament v4) with reorderable tables
  • FaqsRelationManager — drop into any resource whose model uses HasFaqs
  • FaqPlugin for panel registration
  • afea:install:faq installer

Installation

composer require afea/filament-faq
php artisan afea:install:faq

Register in AdminPanelProvider:

->plugin(\Afea\Cms\Faq\Filament\FaqPlugin::make())

Attaching FAQs to another model

1. Use the trait

use Afea\Cms\Faq\Concerns\HasFaqs;

class BlogPost extends Model
{
    use HasFaqs;
}

2. Drop the relation manager into the host resource

use Afea\Cms\Faq\Filament\RelationManagers\FaqsRelationManager;

class BlogPostResource extends Resource
{
    public static function getRelations(): array
    {
        return [FaqsRelationManager::class];
    }
}

3. Query attached FAQs on the front-end

$post->faqs;                 // ordered by pivot `order`
$post->activeFaqs();         // only active FAQs
$post->syncFaqs([$idA, $idB]); // reorder atomically

Three common scenarios

1. Model override

class Faq extends \Afea\Cms\Faq\Models\Faq
{
    public function scopeVerified(Builder $q): Builder
    {
        return $q->active()->whereNotNull('faq_category_id');
    }
}
'models' => ['faq' => \App\Models\Faq::class],

2. Bulk attach FAQs to every blog post

$post->syncFaqs(\Afea\Cms\Faq\Models\Faq::pluck('id')->all());

3. Render a FAQ section inside a Blade view

@foreach ($page->activeFaqs() as $faq)
    <details>
        <summary>{{ $faq->question }}</summary>
        <div class="prose">{!! $faq->answer !!}</div>
    </details>
@endforeach

About

Afea Filament CMS — filament-faq

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages