Introduction of rewriting error handling in FormRequest in Laravel (code example)

01-28-2024

What this article brings to you is an introduction (code example) about rewriting error handling in FormRequest in Laravel, which has certain reference value. Friends who need it can refer to it and hope it will help you. The default validate validation in laravel framework returns to the previous page by default when handling errors, and returns Json when it is ajax. If we want to keep returning Json, we need to rewrite error handling.

As follows: in the Requests directory, just create a new BaseRequest class.

The code is as follows

Copyright Description:No reproduction without permission。

Knowledge sharing community for developers。

Let more developers benefit from it。

Help developers share knowledge through the Internet。

Follow us