ldc-mesbr-app/app/Http/Requests/Customers/UpdateRequest.php
Vincent BRIDIER f0c322c843 - Add API v1
- Add PHPCS
2021-04-27 17:29:47 +02:00

46 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 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 [
'email' => "email|unique:customers,email," . $customer->crm_id . ",crm_id|required",
'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));
}
}
}