Laravel method to implement custom error output _php instance

Source: Internet
Author: User
Tags smarty template

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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.