- How do I add reviews and ratings to any Laravel model with this package?
- Use the package's polymorphic review relationship to attach reviews to any Eloquent model, storing ratings and comments alongside the related model. The package provides helpers and scopes for creating, moderating, and querying reviews, including average and count helpers for star ratings. It is designed to fit Laravel conventions with publishable migrations and configurable validation.
- How do I install roundly-consulting/reviews-for-laravel?
- Install it as a Composer package with roundly-consulting/reviews-for-laravel, then publish and run the package migrations. Publish the config and merge any new keys required by your target version, especially the reviews.resources.author and reviews.resources.reviewable keys added in 1.2.0. Test the upgrade in a branch because 1.2.0 is a feature release with breaking behavior changes.
- What Laravel and PHP versions does reviews-for-laravel 1.2.0 support?
- The exact Laravel and PHP support matrix is defined by the package's composer.json constraints, and the provided evaluation does not pin specific versions for 1.2.0. Check those constraints before upgrading, especially if you rely on the previously required package-toolkit ^1.3.0, enums ^1.1.0, or media-library ^1.1.2 constraints. Treat 1.2.0 as a feature release and validate compatibility in a branch before deploying.
- How do I publish the migrations and configuration for reviews-for-laravel?
- Publish the package migrations and config using Laravel's vendor:publish workflow, then run the migrations to create the review tables. In 1.2.0, publish or merge the reviews.resources.author and reviews.resources.reviewable config keys before deploying. Misconfigured values can throw InvalidConfigurationException naming the offending key, so validate the published config in CI or at boot.
- Why did author.type change from App\Models\User to User in reviews-for-laravel 1.2.0?
- Version 1.2.0 introduces ReviewAuthorResource and ReviewableResource, which wrap related models and emit id and type by default. The default type value is now the class basename, such as User, instead of the fully qualified class name, such as App\Models\User. This is a breaking API contract change for any client or stored payload that parses the full class name. Use a custom JsonResource via reviews.resources.author or reviews.resources.reviewable if you need to preserve or extend the old shape.
- How do I customize the JSON shape of reviews with ReviewAuthorResource and ReviewableResource?
- Set reviews.resources.author and reviews.resources.reviewable to your own JsonResource subclasses. The default resources emit only id and type, so a custom resource is the supported extension point when you need fields such as name, avatar, or title. Register the custom resources, then diff the serialized review payload before and after the change to confirm the API contract.
- How do I avoid N+1 queries when manually creating ReviewResource in Laravel?
- ReviewCollection and single-resource rendering of loaded responses now eager-load per morph type, but code paths that manually construct new ReviewResource($review) or ReviewResource::collection() can still incur N+1 queries. Explicitly eager-load author and reviewable, for example with load('author', 'reviewable'), before building the resource. Audit queues, exports, Blade templates, and manually composed API resources for these code paths.
- What happens when the reviewed model or author is deleted in reviews-for-laravel 1.2.0?
- In 1.2.0, author and reviewable render as null when the related row no longer exists, and both keys are always present in the serialized output. This differs from prior implicit behavior and can break clients that assume the related model is always present. Update contract tests and any non-null assumptions in front-end, mobile, or third-party consumers.
- How should I catch InvalidConfigurationException from reviews-for-laravel config?
- InvalidConfigurationException is thrown for invalid package configuration and names the offending key, which improves failure clarity but adds a new startup or runtime failure surface. Validate the published and merged reviews config in CI, and decide where bootstrapping should catch or surface the exception. Ensure config caching and deployment steps do not leave malformed reviews.resources values in place.
- How do I query approved, recent, or top-rated reviews with reviews-for-laravel?
- Use the package's query scopes to filter reviews by approved status, recency, or top rating. Combine those scopes with the polymorphic review relationship and the average/count helpers to display aggregate scores for a model. This lets you moderate feedback and render star ratings without writing custom query logic from scratch.