From 820fd99e4382131a08e29d86c9570af6fec306e0 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 2 Feb 2026 12:45:03 +0100 Subject: [PATCH 1/2] fix: :bug: show only ratings above 2 (so 3/4/5) #313 --- app/Models/Rating.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/Models/Rating.php b/app/Models/Rating.php index 678e4e56..0396d214 100644 --- a/app/Models/Rating.php +++ b/app/Models/Rating.php @@ -4,6 +4,7 @@ namespace App\Models; use App\Enums\RatingEnum; use App\Traits\Models\ActivityLog; +use App\Models\Customer; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; use Illuminate\Support\Collection; @@ -82,7 +83,7 @@ class Rating extends Model return $model->rate->value(); }), 1), 'ratings' => $model->ratings()->inRandomOrder() - ->take(6)->with('customer')->get()->each(function (Rating $rating) { + ->where('rate', '>', 2)->take(6)->with('customer')->get()->each(function (Rating $rating) { $rating->customer_username = $rating->customer->username; return $rating; }), @@ -94,7 +95,6 @@ class Rating extends Model }); } - /** * Create a SchemaOrg. * From 49310fa1958de29e88de99072740f5a173ea9617 Mon Sep 17 00:00:00 2001 From: Alexis Gousseau Date: Mon, 2 Feb 2026 14:49:44 +0100 Subject: [PATCH 2/2] fix: :bug: dynamically define the target table when storing a new rating #310 --- app/Http/Requests/Fo/StoreRatingRequest.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Http/Requests/Fo/StoreRatingRequest.php b/app/Http/Requests/Fo/StoreRatingRequest.php index 64c482ad..fae2946d 100644 --- a/app/Http/Requests/Fo/StoreRatingRequest.php +++ b/app/Http/Requests/Fo/StoreRatingRequest.php @@ -23,9 +23,11 @@ class StoreRatingRequest extends FormRequest */ public function rules(): array { + $table = $this->rating_type === 'App\Models\Product' ? 'products' : 'recipes'; + return [ 'rate' => 'required|integer|min:0|max:5', - 'rating_id' => 'required|integer|exists:products,id', + 'rating_id' => "required|integer|exists:{$table},id", 'rating_type' => 'required|in:App\\Models\\Product,App\\Models\\Recipe', 'customer_id' => 'required|integer|exists:customers,id', ];