Laravel can customize the output content of an error.
This example describes how Laravel implements custom error output. We will share this with you for your reference. The details are as follows:
Here, we will analyze how laravel verifies the submitted data and customize the output content of the error.
Run commands in the root directory
Php artisan make: request PostUpdateRequest
The PostUpdateRequest file is created in the app \ Http \ Requests directory.
For example, I set
Public function rules () {return ['posts _ title' => 'requestred', // required];}
Add the following messages definition error information to the PostUpdateRequest File
Public function messages () {return ['posts _ title. required' => json_encode (['status' => false, 'message' => 'title required '], JSON_UNESCAPED_UNICODE),];}
Note the preceding JSON_UNESCAPED_UNICODE
To do a test
Echo json_encode (" ");
Output content:
"\ U811A \ u672C \ u4E4B \ u5BB6"
You can't see what this is.
Add Parameters
Echo json_encode ("", JSON_UNESCAPED_UNICODE );
Output:
"Helper's house"
It's normal. I suddenly feel happy.