Home php教程 PHP开发 How to implement custom error output content in Laravel

How to implement custom error output content in Laravel

Dec 20, 2016 pm 03:58 PM

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
Copy after login

will be in the appHttpRequests directory Create a PostUpdateRequest file

For example, I set

public function rules()
{
  return [
    'posts_title' => 'required',//必填
  ];
}
Copy after login

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),
    ];
}
Copy after login

Pay attention to the above JSON_UNESCAPED_UNICODE

to do an experiment

echo json_encode("PHP中文网");
Copy after login

output Content:

"\u811A\u672C\u4E4B\u5BB6"
Copy after login

You can’t see what this is at all

Add a parameter

echo json_encode("PHP中文网", JSON_UNESCAPED_UNICODE);
Copy after login

Output:

"PHP中文网"
Copy after login

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!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)