ldc-mesbr-app/app/Http/Requests/Customers/BasketRequest.php
2025-11-07 11:08:02 +01:00

45 lines
1.1 KiB
PHP

<?php
namespace App\Http\Requests\Customers;
use App\Http\Resources\StatusResource;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Http\Exceptions\HttpResponseException;
class BasketRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'refcamp' => 'string|exists:campagne,camp_id|required',
'hashcode' => 'string|exists:customers,hashcode|required'
];
}
protected function failedValidation(Validator $validator)
{
if ($this->wantsJson()) {
throw new HttpResponseException(response()->json(new StatusResource([
'status' => 'KO',
'code' => 422,
'message' => $validator->errors()->messages()
]), 422));
}
}
}