Skip to content

Instantly share code, notes, and snippets.

@hungthai1401
Created October 4, 2018 09:36
Show Gist options
  • Save hungthai1401/406e44947b696db44c86d0fbbb7e2d77 to your computer and use it in GitHub Desktop.
Save hungthai1401/406e44947b696db44c86d0fbbb7e2d77 to your computer and use it in GitHub Desktop.
Form request return json
use Illuminate\Validation\ValidationException;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
/**
* Handle a failed validation attempt.
*
* @param \Illuminate\Contracts\Validation\Validator $validator
* @return void
*
* @throws HttpResponseException
*/
protected function failedValidation(Validator $validator) : void
{
$errors = (new ValidationException($validator))->errors();
throw new HttpResponseException(format_response(ResultCode::ERROR, null, $errors));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment