itmosoft / laravel-product-questions
Product questions and answers with moderation, customer attribution, and helpfulness voting for Laravel applications.
Package info
github.com/ITMOSOFT/laravel-product-questions
pkg:composer/itmosoft/laravel-product-questions
Requires
- php: ^8.3
- illuminate/database: ^12.0 || ^13.0
- illuminate/support: ^12.0 || ^13.0
Requires (Dev)
- orchestra/testbench: ^10.0 || ^11.0
- phpunit/phpunit: ^11.0 || ^12.0
Suggests
None
Provides
None
Conflicts
None
Replaces
None
README
Product questions and answers with moderation and customer attribution for Laravel 12 and 13.
Features
- Ask questions against any Eloquent product model.
- Optional polymorphic asker/customer association.
- Add answers with optional polymorphic responder association.
- Pending, approved and rejected moderation states.
- Published question query scoped to a product.
- Approved answers eager-loaded with published questions.
- Metadata support.
- Transactional question deletion with answer cleanup.
- Configurable table prefix.
Requirements
- PHP 8.3+
- Laravel 12 or 13
Installation
composer require itmosoft/laravel-product-questions php artisan vendor:publish --tag=itmosoft-product-questions-config php artisan migrate
By default, migrations create itmosoft_product_questions and itmosoft_product_answers. Configure table_prefix before migrating if needed.
Ask a product question
use ItmoSoft\ProductQuestions\ProductQuestionManager; $manager = app(ProductQuestionManager::class); $question = $manager->ask( product: $product, question: 'Does this product include a warranty?', asker: auth()->user(), );
Questions are pending and unpublished by default.
Add an answer
$answer = $manager->answer( question: $question, answer: 'Yes, it includes a one-year warranty.', responder: auth()->user(), );
Answers are also pending and unpublished by default.
Moderate content
$manager->moderateQuestion($question, 'approved'); $manager->moderateAnswer($answer, 'approved'); // Other supported status: rejected
Only approved and published questions are returned by publishedForProduct().
Display approved Q&A
$questions = $manager->publishedForProduct($product)->paginate(20);
The query eager-loads only approved, published answers.
Important scope and production notes
- The package provides persistence and moderation primitives, not public routes, controllers, admin screens, notifications, spam detection, rate limiting, or frontend components.
- Product, asker and responder are polymorphic Eloquent models. Integrate with your product/customer/user models in the host application.
- Enforce authorization, request validation, abuse prevention, tenant scoping and content sanitization in your application.
statusis validated against the configuredallowed_statuseslist. The default statuses arepending,approved, andrejected.- The package does not implement voting, accepted answers, product-specific staff permissions, or verified-purchase checks.
- Deleting a question deletes its answers in a transaction. Configure database foreign keys appropriately for your target driver.
- The package uses text fields for content; escape output in your views to prevent cross-site scripting.
Testing
composer install
composer validate --strict
composer test
License
MIT. See LICENSE.