-
Notifications
You must be signed in to change notification settings - Fork 81
Open
Description
Hi,
Thanks for some great Laravel practice projects! One quick bug I noticed is in the book review project when we add the withAvgRating and withReviewsCount scope, the previous Popular and HighestRated scopes are not passing along the $from and $to date values so the project's last month / last 6 months filtering breaks.
Suggested update below passes the $from and $to variables through:
public function scopeWithReviewsCount(Builder $query, $from = null, $to = null): Builder
{
return $query->withCount([
'reviews' => fn (Builder $q) => $this->dateRangeFilter($q, $from, $to)
]);
}
public function scopeWithAvgRating(Builder $query, $from = null, $to = null): Builder
{
return $query->withAvg([
'reviews' => fn (Builder $q) => $this->dateRangeFilter($q, $from, $to)
], 'rating');
}
public function scopePopular(Builder $query, $from = null, $to = null): Builder
{
return $query->withReviewsCount($from, $to)->orderBy('reviews_count', 'desc');
}
public function scopeHighestRated(Builder $query, $from = null, $to = null): Builder
{
return $query->withAvgRating($from, $to)->orderBy('reviews_avg_rating', 'desc');
}
Let me know if you'd prefer me to submit a PR for this - wasn't sure what you'd prefer.
Metadata
Metadata
Assignees
Labels
No labels