Skip to content

Instantly share code, notes, and snippets.

@cuonghuynh
Created November 22, 2016 03:15
Show Gist options
  • Save cuonghuynh/9cc0d0f3eb390d416ebfb5a1a9e318bd to your computer and use it in GitHub Desktop.
Save cuonghuynh/9cc0d0f3eb390d416ebfb5a1a9e318bd to your computer and use it in GitHub Desktop.
Turning off Validation Redirects
<?php
namespace App\Http\Requests;
use Illuminate\Http\JsonResponse;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exception\HttpResponseException;
abstract class BaseRequest extends FormRequest
{
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return mixed
*/
protected function failedValidation(Validator $validator)
{
throw new HttpResponseException($this->response([
'errors' => $this->formatErrors($validator)
]));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment