ldc-mesbr-app/app/Http/Requests/Customers/StoreRequest.php

47 lines
1.1 KiB
PHP
Raw Permalink Normal View History

2021-04-20 19:51:30 +02:00
<?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 StoreRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
2025-04-03 09:30:16 +02:00
* @return boolean
2021-04-20 19:51:30 +02:00
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
2021-08-13 11:48:06 +02:00
'hashcode' => 'string|required',
2021-06-29 16:04:22 +02:00
'email' => 'email|required',
2021-04-20 19:51:30 +02:00
'country' => 'string|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));
}
}
}