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

47 lines
1.1 KiB
PHP
Raw 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 UpdateRequest 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()
{
$customer = $this->route('customer');
return [
2021-04-27 17:29:47 +02:00
'email' => "email|unique:customers,email," . $customer->crm_id . ",crm_id|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));
}
}
}