agence-adeliom/easy-faq-bundle
Basic FAQ system for Symfony EasyAdmin: manage FAQ entries and categories via CRUD, with configurable FAQ page root path. Supports Symfony 6.4/7.x (PHP 8.2+), with older branches for Symfony 5.4/6.x and 4.4/5.x.
Installation
composer require agence-adeliom/easy-faq-bundle
Ensure your composer.json includes the GitHub recipes endpoint for Flex compatibility.
Database Setup Run migrations:
php artisan migrate # Laravel equivalent (adjust if using Symfony CLI)
(Note: The bundle is Symfony-focused, but Laravel users can adapt Doctrine migrations via doctrine/dbal or laravel-doctrine/orm.)
First Use Case
Access the FAQ CRUD interface in EasyAdmin (/admin/faq). Create a FAQ entry with:
config/packages/easy_admin.yaml for FAQ CRUD configuration.src/Entity/FAQ.php (customize fields/methods as needed).templates/easy_faq/ for frontend display.Admin Management
/admin/faq.config/easy_admin.yaml:
easy_admin:
entities:
FAQ:
class: App\Entity\FAQ
list:
fields: ['question', 'active', 'order']
form:
fields: ['question', 'answer', 'active', 'order']
Frontend Display
// Laravel (adapted from Symfony)
$faqs = $entityManager->getRepository(FAQ::class)->findBy(['active' => true]);
return view('faq.index', compact('faqs'));
{% for faq in faqs %}
<div class="faq-item">
<h3>{{ faq.question }}</h3>
<p>{{ faq.answer }}</p>
</div>
{% endfor %}
API Access (Optional)
Route::get('/api/faqs', function () {
return FAQ::where('active', true)->orderBy('order')->get();
});
Laravel-Symfony Bridge:
doctrine/orm for Doctrine compatibility in Laravel:
composer require doctrine/orm
config/packages/doctrine.yaml to match Laravel’s database settings.Custom Fields:
Extend the FAQ entity to add fields (e.g., category, tags):
// src/Entity/FAQ.php
#[ORM\Column(type: 'string', length: 255, nullable: true)]
private ?string $category = null;
EasyAdmin Extensions:
Add filters/sorting in easy_admin.yaml:
list:
actions: ['show', 'edit', 'delete']
filters: ['question', 'active']
sort: ['order']
Localization:
Use Symfony’s translation system or Laravel’s trans() helper for multilingual FAQs.
Doctrine Migrations in Laravel
laravel-doctrine/orm.App\Entity\FAQ is properly namespaced and annotated.EasyAdmin Version Mismatch
composer require easycorp/easyadmin-bundle:^3.4
spatie/laravel-easyadmin as a wrapper.Template Overrides
templates/easy_faq/ may not exist by default. Create them if extending:
templates/
easy_faq/
crud/
index.html.twig
Ordering Quirks
order field is numeric but may not auto-sort in EasyAdmin. Add a custom OrderableInterface or use a Sortable trait.Missing CRUD Route:
Ensure FAQ is listed in easy_admin.yaml and the bundle is enabled in config/bundles.php (Symfony) or config/app.php (Laravel).
Database Errors:
Check migration files in src/Migrations/ for Laravel or migrations/ for Symfony. Run:
php artisan doctrine:migrations:migrate # Laravel (if using doctrine/orm)
Symfony-Specific Issues:
php bin/console cache:clear
php artisan cache:clear.Custom FAQ Types
Extend the FAQ entity to support different content types (e.g., rich text, images):
#[ORM\Column(type: 'json', nullable: true)]
private ?array $media = null;
Event Listeners Hook into FAQ lifecycle events (e.g., log changes):
// src/EventListener/FAQListener.php
#[AsEventListener(event: 'prePersist', method: 'onPrePersist')]
public function onPrePersist(FAQ $faq) {
// Add logic (e.g., auto-generate slugs)
}
API Resources (Laravel) Use Laravel’s API Resources to shape FAQ responses:
php artisan make:resource FAQResource
// app/Http/Resources/FAQResource.php
public function toArray($request) {
return [
'question' => $this->question,
'answer' => $this->answer,
'active' => $this->active,
];
}
Search Functionality Add a search field in EasyAdmin:
list:
fields: ['question', 'active']
search:
fields: ['question']
For Laravel, use a scope:
public function scopeSearch($query, $search) {
return $query->where('question', 'LIKE', "%{$search}%");
}
How can I help you explore Laravel packages today?