How to return a custom error message using this format?
$this->validate($request, [ 'thing' => 'required' ]);
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.
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.
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.
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.
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'] );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With