1

I'm using this code to validate my $request variable:

$validatedData = $request->validate([
    'name' => 'string|required|max:255',
    'lead' => 'nullable|string',
    ...
]);

After this I want to return error messages as a JSON object, use this code:

return response()->json([
    'errors' => $validatedData->errors()
]);

And here it says $ValidateData is an array. That's true, but where can I find the validation error messages? I checked the official Laravel 5.7 documentation, but it's not clear.

Any idea?

1 Answer 1

2

If you need customoize the error messages, just need to read this in laravel documentation.

https://laravel.com/docs/5.7/validation#customizing-the-error-messages https://laravel.com/docs/5.7/validation#working-with-error-messages

$messages = [
    'same'    => 'The :attribute and :other must match.',
    'size'    => 'The :attribute must be exactly :size.',
    'between' => 'The :attribute value :input is not between :min - :max.',
    'in'      => 'The :attribute must be one of the following types: :values',
];

$validator = Validator::make($input, $rules, $messages);

I hope, i could help for you.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.