The examples in this article describe the Laravel method for implementing custom error output. Share to everyone for your reference, specific as follows:
Here to analyze the Laravel for the submitted data validation, how to customize the error output content
To run a command under the root directory
PHP Artisan make:request postupdaterequest
Postupdaterequest files are created in the App\http\requests directory
Like I set
Public function rules ()
{return
[
' posts_title ' => ' required ', required
];
}
Define error messages in the Postupdaterequest file add the following messages aspects
Public function messages () {return
['
posts_title.required ' =>json_encode (' status ' =>false, ' Message ' => ' title must be filled '],json_unescaped_unicode '),
];
}
Watch the top json_unescaped_unicode.
To do an experiment.
echo Json_encode ("cloud-dwelling community");
Output content:
"\u811a\u672c\u4e4b\u5bb6"
You can't see what this is.
Add a parameter
echo Json_encode ("cloud-dwelling community", json_unescaped_unicode);
Output:
"Cloud-dwelling community"
Normal, suddenly feel happy
More interested in laravel related content readers can view the site topics: "Laravel Framework Introduction and Advanced Course", "PHP Excellent Development Framework Summary", "Smarty Template Primer Tutorial", "PHP date and Time usage summary", "PHP object-oriented Program Design Introductory Course ", PHP string (String) Usage summary," PHP+MYSQL Database operation Introduction Tutorial "and" PHP common database Operation Skills Summary "
I hope this article will help you with the PHP program design based on Laravel framework.