Developer docs Core 2.2 · Pro 1.x

Search documentation

Search Core and Pro guides, including code examples.

CORE · FREE / MIT

Queries & statistics.

Install the open-source review engine, connect a model, and build your own review experience.

← All Core topics

Queries and statistics

Core returns approved reviews by default. Request pending reviews only from an authorized private workflow.

$published = $product->getReviews();
$pending = $product->getReviews(false);
$withoutRatings = $product->getReviews(true, false);

$supportReviews = $product->getReviewsByDepartment('support');
$fiveStarReviews = $product->getReviewsByRating(
    5, department: 'support'
);

$total = $product->totalReviews();
$supportTotal = $product->totalDepartmentReviews('support');

$overall = $product->averageRating('overall');
$averages = $product->averageRatings();
$supportAverage = $product->averageRatingByDepartment('support', 'overall');

$allCriteriaAverage = $product->overallAverageRating();
$distribution = $product->ratingCounts('default');
$stats = $product->ratingStats('default');

ratingStats() returns counts, percentages, and total. Core's distribution/statistics APIs count rating rows across criteria, not one overall score per review. Likewise, getReviewsByRating() matches a review with any criterion at the requested value. For an overall-only breakdown or filter, scope the ratings relationship to your chosen key. Pro's summary and filters do this using listing.summary_rating_key.

Use the relationship for pagination, eager loading, or custom criteria:

$reviews = $product->reviews()
    ->where('department', 'default')
    ->where('approved', true)
    ->whereHas('ratings', fn ($query) => $query
        ->where('key', 'overall')
        ->where('value', 5))
    ->with(['ratings', 'user'])
    ->latest()
    ->paginate(10);

Only eager-load optional relationships after installing their tables. Avoid unapproved content in public JSON, caches, or summaries.