Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to return custom error message from controller method validation

How to return a custom error message using this format?

$this->validate($request, [   'thing' => 'required' ]); 
like image 682
cmac Avatar asked Oct 16 '16 05:10

cmac


People also ask

How do you show custom validator error message in validation summary?

In order for the Validator 's error message to display in the ValidationSummary , you need to set the Validator s Display="none" . I also set Text="" . C.C. C.C.

How to Display error message in Spring Boot?

The most basic way of returning an error message from a REST API is to use the @ResponseStatus annotation. We can add the error message in the annotation's reason field. Although we can only return a generic error message, we can specify exception-specific error messages.

What happens when a validator fails?

If validation fails during a traditional HTTP request, a redirect response to the previous URL will be generated. If the incoming request is an XHR request, a JSON response containing the validation error messages will be returned.

What is API validation error?

If the API fails to validate a request, it will respond with a 400 validation error message (JSON or XML) describing the issue. The below validation errors are the most common and will respond with some details, including a list of validation messages.


1 Answers

to get custom error message you need to pass custom error message on third parameter,like that

$this->validate(     $request,      ['thing' => 'required'],     ['thing.required' => 'this is my custom error message for required'] ); 
like image 194
Imtiaz Pabel Avatar answered Oct 14 '22 00:10

Imtiaz Pabel