fix: 🐛 dynamically define the target table when storing a new rating #310

This commit is contained in:
Alexis Gousseau 2026-02-02 14:49:44 +01:00
parent 0b927200e9
commit 49310fa195

View file

@ -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',
];