I am using Laravel request to validate in my controller the requested data
and here is my request file data
I am facing two challanges
- first I am not able to return custom message using static function
- I am not able to send single message as we send in controller validation using errors()->first().
By defalut it is returning like that
but I want like below SS
Is there I can send first message using request ?
Advertisement
Answer
-For custom message
Laravel Documents customizing-the-error-messages
-For return single error message
//In Request use IlluminateContractsValidationValidator; use IlluminateHttpExceptionsHttpResponseException; protected function failedValidation(Validator $validator) { throw new HttpResponseException(response()->json([ 'success' => false, 'message' =>$validator->errors()->first(), 'data' => null, ], 422)); }