### Install laravel-faq via Composer Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Install the package via Composer. ```bash composer require jeffersongoncalves/laravel-faq ``` -------------------------------- ### Publish and run migrations Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Publish and run the package migrations. ```bash php artisan vendor:publish --tag="faq-migrations" php artisan migrate ``` -------------------------------- ### Create and translate a FaqCategory Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Create a FaqCategory with translatable name, slug, order, and active flag. Demonstrates getTranslation and setTranslation methods from spatie/laravel-translatable. ```php use JeffersonGoncalves\Faq\Models\FaqCategory; $category = FaqCategory::create([ 'name' => ['en' => 'Billing', 'pt_BR' => 'Faturamento'], 'slug' => 'billing', 'order' => 1, 'is_active' => true, ]); $category->getTranslation('name', 'pt_BR'); // 'Faturamento' $category->setTranslation('name', 'es', 'Facturación'); $category->save(); ``` -------------------------------- ### Publish config file Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Publish the config file (optional). ```bash php artisan vendor:publish --tag="faq-config" ``` -------------------------------- ### Create and access a Faq Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Create a Faq with optional category, translatable question and answer. Accessing $faq->question resolves the current locale with fallback; $faq->category returns the related FaqCategory or null. ```php use JeffersonGoncalves\Faq\Models\Faq; $faq = Faq::create([ 'faq_category_id' => $category->id, // nullable — FAQs can exist without a category 'question' => ['en' => 'How do I update my payment method?'], 'answer' => ['en' => 'Go to Settings > Billing and click "Update payment method".'], 'order' => 1, 'is_active' => true, ]); $faq->question; // resolved for the current app locale, with fallback $faq->category; // the related FaqCategory, or null ``` -------------------------------- ### Run tests with composer test Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Run the test suite for the package. ```bash composer test ``` -------------------------------- ### Configure locales in config/faq.php Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Define supported translation locales, mirroring app.available_locales or falling back to the app locale. ```php 'locales' => config('app.available_locales') ? array_keys(config('app.available_locales')) : [config('app.locale', 'en')], ``` -------------------------------- ### Configure table names in config/faq.php Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Override the default table names for FAQ categories and FAQs. ```php 'table_names' => [ 'categories' => 'faq_categories', 'faqs' => 'faqs', ], ``` -------------------------------- ### Apply active and ordered scopes Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Use the active and ordered scopes on FaqCategory and Faq models, including querying FAQs through a category relationship. ```php FaqCategory::active()->ordered()->get(); Faq::active()->ordered()->get(); $category->faqs()->active()->ordered()->get(); ``` -------------------------------- ### Use spatie translatable methods on Faq Source: https://github.com/jeffersongoncalves/laravel-faq/blob/main/README.md Use the spatie/laravel-translatable API on Faq models: getTranslation, setTranslation, getTranslations, and translate methods. ```php $faq->getTranslation('question', 'pt_BR'); $faq->setTranslation('question', 'pt_BR', 'Como atualizo minha forma de pagamento?'); $faq->getTranslations('question'); // ['en' => '...', 'pt_BR' => '...'] $faq->translate('question', 'pt_BR'); ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.