Model
The model used isShopper\Core\Models\Review. It implements Shopper\Core\Models\Contracts\Review. Unlike products or brands, the Review model is not configurable via config/shopper/models.php and has no admin model wrapper.
Products gain review capabilities through the InteractsWithReviews trait, which implements the Shopper\Core\Contracts\HasReviews interface. This is already applied to the Product model.
Database Schema
| Column | Type | Nullable | Default | Description |
|---|---|---|---|---|
id | bigint | no | auto | Primary key |
rating | integer | no | - | Rating value (typically 1-5) |
title | text | yes | null | Review title |
content | text | yes | null | Review content |
is_recommended | boolean | no | false | Customer recommends product |
approved | boolean | no | false | Review approval status |
reviewrateable_id | bigint | no | - | Polymorphic relation ID (product) |
reviewrateable_type | string | no | - | Polymorphic relation type |
author_id | bigint | no | - | Polymorphic relation ID (user) |
author_type | string | no | - | Polymorphic relation type |
created_at | timestamp | yes | null | Creation timestamp |
updated_at | timestamp | yes | null | Last update timestamp |
Relationships
Reviewrateable (Product)
Author (User)
HasReviews Contract
Products implement theHasReviews contract via the InteractsWithReviews trait:
Rating Methods
Getting Ratings
Rating Counts
Average Ratings
Rating Percentage
Creating Reviews
Via Product Model
Via Review Model
Direct Creation
Updating Reviews
Approval Management
Deleting Reviews
Retrieving Reviews
Configuration
Disabling Reviews
If your store doesn’t need product reviews, disable the feature inconfig/shopper/features.php:
Permissions
The admin panel generates five permissions for review management:| Permission | Description |
|---|---|
browse_reviews | View the reviews list |
read_reviews | View a single review |
add_reviews | Create new reviews |
edit_reviews | Edit existing reviews |
delete_reviews | Delete reviews |
Components
To customize the admin UI for review management:config/shopper/components/review.php:
Storefront Example
Review Display
Review Submission
Review Management (Admin)
Blade Template Example
Use Cases
| Method | Use Case |
|---|---|
averageRating() | Display product rating stars |
countRating() | Show total review count |
ratingPercent() | Build rating distribution chart |
getApprovedRatings() | Display reviews on product page |
getNotApprovedRatings() | Admin review moderation queue |
getRecentUserRatings() | Customer review history |