ldc-legaulois/app/Http/Requests/Fo/StoreRatingRequest.php

49 lines
1.2 KiB
PHP

<?php
namespace App\Http\Requests\Fo;
use Illuminate\Foundation\Http\FormRequest;
class StoreRatingRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return boolean
*/
public function authorize(): bool
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
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:{$table},id",
'rating_type' => 'required|in:App\\Models\\Product,App\\Models\\Recipe',
'customer_id' => 'required|integer|exists:customers,id',
];
}
/**
* Get the error messages for the defined validation rules.
*
* @return array<string, string>
*/
public function messages(): array
{
return [
'rate' => trans('notation'),
'rating_id' => trans('élément ciblé'),
'customer_id' => trans('utilisateur connecté'),
];
}
}