You can definitely create your own Exception class and instruct laravel to use it to reply the response.
Assuming your own custom Exception class is Illuminate\Http\Exceptions\HttpResponseException you only need to override failedValidation method in your form request class and have something like this.
use Illuminate\Http\Response;
use Illuminate\Contracts\Validation\Validator;
use Illuminate\Http\Exceptions\HttpResponseException;
...
/**
* @param Validator $validator
* @throws HttpResponseException
*/
protected function failedValidation(Validator $validator)
{
throw new HttpResponseException(
response()->json(
[
'message' => 'My message',
'errors' => $validator->errors()->get('*') //or ->all() instead of get()
],
Response::HTTP_UNPROCESSABLE_ENTITY
)
);
}
The above would ensure your custom error response format is used. You can also add it to a Trait and include it in all your request class or just create a base Request class that others should extend.
FormRequestan placing the validation rules inside