How to implement custom error output content in Laravel
The example in this article describes how Laravel implements customized error output content. Share it with everyone for your reference, the details are as follows:
Here is an analysis of laravel's verification of submitted data, how to customize the content of the error output
Run the command in the root directory
php artisan make:request PostUpdateRequest
will be in the appHttpRequests directory Create a PostUpdateRequest file
For example, I set
public function rules() { return [ 'posts_title' => 'required',//必填 ]; }
Add the following messages in the PostUpdateRequest file to define the error message
public function messages(){ return [ 'posts_title.required' =>json_encode( ['status'=>false,'message'=>'标题必须填'],JSON_UNESCAPED_UNICODE), ]; }
Pay attention to the above JSON_UNESCAPED_UNICODE
to do an experiment
echo json_encode("PHP中文网");
output Content:
"\u811A\u672C\u4E4B\u5BB6"
You can’t see what this is at all
Add a parameter
echo json_encode("PHP中文网", JSON_UNESCAPED_UNICODE);
Output:
"PHP中文网"
It’s normal, and suddenly I feel happy
I hope this article The above will be helpful to everyone in PHP programming based on the Laravel framework.
For more articles on how to implement custom error output content in Laravel, please pay attention to the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

