- How do I install codebyray/laravel-review-rateable in a Laravel app?
- Install it with Composer using composer require codebyray/laravel-review-rateable, then follow the package README for any service provider, configuration, and migration steps. Laravel package auto-discovery should handle provider registration in typical apps, but verify this for your Laravel version. For the 2.3.0 criterion-rating additions described here, the changes are additive and do not require a schema change.
- Can I attach reviews and star ratings to any Eloquent model?
- Yes. The package uses polymorphic relationships so reviews and ratings can be attached to products, posts, users, or other Eloquent models. You add the provided trait and contract-style integration to the models you want to make reviewable and rateable. This keeps the feature reusable across multiple model types instead of tying it to a single table.
- How do I get average ratings and rating breakdowns for a model?
- Use the package helpers exposed on the reviewable model to read average scores, rating counts, and distributions. In 2.3.0 you can scope those reads by a rating key or criterion with methods such as ratingCountsForKey and ratingStatsForKey. For review lists filtered by a specific rating value and key, use getReviewsByRatingForKey.
- What is a rating key or criterion in this package?
- A rating key, also called a criterion, is a named dimension you can rate separately, such as overall, quality, or value. Version 2.3.0 adds criterion-scoped reads for counts, aggregate statistics, and filtered reviews. Existing rating query methods retain their all-criteria behavior, so the new axis is additive rather than a breaking change.
- How do approval workflows work for reviews?
- The package includes an approval moderation state so reviews can be marked approved or unapproved. The package does not decide your policy for you, so your application must consistently filter unapproved reviews where appropriate. Be careful with default scoping because a wrong scope can return plausible but incorrect ratings.
- Can users upload images with their reviews?
- Yes. The package supports optional image attachments on reviews. Treat upload validation, storage, and image processing as application responsibilities and follow your normal Laravel file upload and security practices. Check the README for the exact attachment configuration and model fields.
- Which Laravel and PHP versions does laravel-review-rateable support?
- The provided notes do not state the PHP and Laravel version matrix or test coverage for version 2.3.0. Check the package composer.json, README, and CI configuration before adopting it. That check is especially important if you are on older Laravel releases or a newer PHP version.
- How do I avoid empty or split rating distributions from bad rating key data?
- Rating key data quality is the main risk because nulls, case variance, free-text keys, and legacy rows can make distributions split or return zero without throwing an exception. Audit historical rows before enabling criterion-scoped reporting. Prefer enumerated or validated rating keys at write time and normalize existing values such as overall, Overall, and OVERALL.
- How should I test code that uses CriterionRatingContract?
- Bind CriterionRatingContract in a service provider and inject it rather than resolving it with app at call sites. That gives you a seam to mock or decorate the contract in tests and to swap in caching or denormalized reads later. Keep controllers and Blade views behind your own thin read service so tests exercise one integration point.
- Is laravel-review-rateable suitable for large production review tables?
- It can be, but the provided notes flag aggregate query cost on large review tables as a medium risk because indexing, caching, and precomputation are not described. Confirm whether your composite indexes support rateable_type, rateable_id, rating_key, department, and approved filters. Also check whether ratingStatsForKey aggregates in SQL or hydrates models in PHP, since PHP-side aggregation caps usable scale.