This commit is contained in:
43
api/app/Http/Requests/FormRequest.php
Normal file
43
api/app/Http/Requests/FormRequest.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
use Illuminate\Foundation\Http\FormRequest as LaravelFormRequest;
|
||||
use Illuminate\Http\JsonResponse;
|
||||
use Illuminate\Http\Exceptions\HttpResponseException;
|
||||
use Illuminate\Validation\ValidationException;
|
||||
|
||||
abstract class FormRequest extends LaravelFormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
abstract public function authorize();
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
abstract public function rules();
|
||||
|
||||
/**
|
||||
* Handle a failed validation attempt.
|
||||
*
|
||||
* @param \Illuminate\Contracts\Validation\Validator $validator
|
||||
* @return void
|
||||
*
|
||||
* @throws \Illuminate\Validation\HttpResponseException
|
||||
*/
|
||||
protected function failedValidation(Validator $validator)
|
||||
{
|
||||
$errors = (new ValidationException($validator))->errors();
|
||||
|
||||
throw new HttpResponseException(
|
||||
response()->json($errors, JsonResponse::HTTP_UNPROCESSABLE_ENTITY)
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user