Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i send error response of validation error of fields in lumen/laravel ? #150

Closed
royrakesh opened this issue Jan 5, 2020 · 2 comments

Comments

@royrakesh
Copy link

My code
image

I want to send array of fields to response which has error but i got response in string

Response

image

@royrakesh royrakesh changed the title How can i send error response of validation message in lumen ? How can i send error response of validation error of fields in lumen/laravel ? Jan 5, 2020
@flugg
Copy link
Owner

flugg commented Jan 5, 2020

Hi, the second paramter of error is for messages and can only contain strings. The data method should do what you're after:

return responder()->error('errors')->data($validator->errors())->respond();

However, the package also automatically catches ValidationException and returns a neatly structured error response if you've followed the steps in the Handling Exceptions chapter of the documentation.

@royrakesh
Copy link
Author

Thanks that works with one modification

return responder()->error('errors')->data($validator->errors()->toArray())->respond();

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants