25 lines
663 B
PHP
25 lines
663 B
PHP
<?php
|
|
|
|
namespace App\Traits\Requests\Api;
|
|
|
|
use Illuminate\Contracts\Validation\Validator;
|
|
use Illuminate\Http\Exceptions\HttpResponseException;
|
|
|
|
trait HasLaravelFailedValidation
|
|
{
|
|
/**
|
|
* Set manually a failed ajax response.
|
|
*
|
|
* @param \Illuminate\Contracts\Validation\Validator $validator
|
|
* @return void
|
|
* @throws \Illuminate\Http\Exceptions\HttpResponseException Override ajax code error.
|
|
*/
|
|
protected function failedValidation(Validator $validator): void
|
|
{
|
|
$response = response()->json([
|
|
'errors' => $validator->errors(),
|
|
], 422);
|
|
|
|
throw new HttpResponseException($response);
|
|
}
|
|
}
|