laravel form validation
Use request method
<code>E:<span>\Laravel</span><span>\blog</span>>php artisan make:request ArticleRequest</code>
Generate ArticleRequest.php under app/http/request and modify it as follows
<code><?php namespace App\Http\Requests; use App\Http\Requests\Request; <span><span>class</span><span>ArticleRequest</span><span>extends</span><span>Request</span></span> { <span>/** * Determine if the user is authorized to make this request. * * <span>@return</span> bool */</span> public function authorize() { <span>return</span><span>true</span>; } <span>/** * Get the validation rules that apply to the request. * * <span>@return</span> array */</span> public function rules() { <span>return</span> [ <span>//</span><span>"name"</span>=><span>"<strong>require</strong>d"</span>, ]; } } </code>
rules are verification rules
authorize To return true
<code>{<span>!</span><span>!</span><span>Form</span>::<span>open</span>([<span>"url"</span>=><span>"/site/store"</span>]) <span>!</span><span>!</span>} {<span>!</span><span>!</span><span>Form</span>::<span>text</span>(<span>"name"</span>,<span>"aa"</span>,[<span>"class"</span>=><span>"form-controller"</span>,<span>"id"</span>=><span>"t"</span>]) <span>!</span><span>!</span>} {<span>!</span><span>!</span><span>Form</span>::<span>submit</span>() <span>!</span><span>!</span>} {<span>!</span><span>!</span><span>Form</span>::<span>close</span>() <span>!</span><span>!</span>} {{--{{$<span>errors</span>}}--}} {{--{<span>!</span><span>!</span> $<span>errors</span><span>!</span><span>!</span>}--}} //用于显示验证不通过的错误信息 @<span>if</span>($<span>errors</span><span>-></span><span>any</span>()) @<span>foreach</span>($<span>errors</span><span>-></span><span>all</span>() <span>as</span> $<span>err</span>) {<span>!</span><span>!</span> $<span>err</span><span>!</span><span>!</span>} @<span>endforeach</span> @<span>endif</span></code>
The controller only needs RequestsArticleRequest. The parameter type can be the request above
<code><span>public</span><span><span>function</span><span>store</span><span>(Requests\ArticleRequest <span>$req</span>)</span>{</span> dd(<span>"fdsaf"</span>); }</code>
Execute the method after the verification is passed, without redirecting the form page
Use validate method
The request with normal controller parameters
The second parameter of validate is the same as the rules above
<code><span>public</span><span><span>function</span><span>store</span><span>(Request <span>$req</span>)</span>{</span><span>$this</span>->validate(<span>$req</span>,[<span>"name"</span>=><span>"<strong>require</strong>d"</span>]); dd(<span>"fdsaf"</span>); }</code>
Chinese problem
config/app.php
locale changed to Chinese
<code><span>'locale'</span> => <span>'zh'</span>,</code>
Copy the resources/lang/en folder in the project and change it to zh
Correspondingly modified to Chinese
If the field must be modified,
<code><span>'<strong>require</strong>d'</span> => <span>'The :attribute field 必须.'</span>,</code>
').addClass('pre-numbering').hide(); in
resources/lang/zh/validation.php; $(this).addClass('has-numbering').parent().append($numbering); for (i = 1; i ').text(i)); }; $numbering.fadeIn(1700); }); });The above introduces laravel form validation, including require aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

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



Many users will choose the Huawei brand when choosing smart watches. Among them, Huawei GT3pro and GT4 are very popular choices. Many users are curious about the difference between Huawei GT3pro and GT4. Let’s introduce the two to you. . What are the differences between Huawei GT3pro and GT4? 1. Appearance GT4: 46mm and 41mm, the material is glass mirror + stainless steel body + high-resolution fiber back shell. GT3pro: 46.6mm and 42.9mm, the material is sapphire glass + titanium body/ceramic body + ceramic back shell 2. Healthy GT4: Using the latest Huawei Truseen5.5+ algorithm, the results will be more accurate. GT3pro: Added ECG electrocardiogram and blood vessel and safety

Both curl and Pythonrequests are powerful tools for sending HTTP requests. While curl is a command-line tool that allows you to send requests directly from the terminal, Python's requests library provides a more programmatic way to send requests from Python code. The basic syntax for converting curl to Pythonrequestscurl command is as follows: curl[OPTIONS]URL When converting curl command to Python request, we need to convert the options and URL into Python code. Here is an example curlPOST command: curl-XPOST https://example.com/api

1. Install the requests library. Because the learning process uses the Python language, Python needs to be installed in advance. I installed Python 3.8. You can check the Python version you installed by running the command python --version. It is recommended to install Python 3.X or above. After installing Python, you can directly install the requests library through the following command. pipinstallrequestsPs: You can switch to domestic pip sources, such as Alibaba and Douban, which are fast. In order to demonstrate the function, I used nginx to simulate a simple website. After downloading, just run the nginx.exe program in the root directory.

Why Snipping Tool Not Working on Windows 11 Understanding the root cause of the problem can help find the right solution. Here are the top reasons why the Snipping Tool might not be working properly: Focus Assistant is On: This prevents the Snipping Tool from opening. Corrupted application: If the snipping tool crashes on launch, it might be corrupted. Outdated graphics drivers: Incompatible drivers may interfere with the snipping tool. Interference from other applications: Other running applications may conflict with the Snipping Tool. Certificate has expired: An error during the upgrade process may cause this issu simple solution. These are suitable for most users and do not require any special technical knowledge. 1. Update Windows and Microsoft Store apps

The Chinese meaning of request is "request". It is a global variable in PHP and is an array containing "$_POST", "$_GET" and "$_COOKIE". The "$_REQUEST" variable can obtain data and COOKIE information submitted by POST or GET.

Requests inherits all features of urllib2. Requests supports HTTP connection persistence and connection pooling, the use of cookies to maintain sessions, file uploading, automatic determination of the encoding of response content, and automatic encoding of internationalized URLs and POST data. Installation method uses pip to install $pipinstallrequestsGET request basic GET request (headers parameters and parmas parameters) 1. The most basic GET request can directly use the get method 'response=requests.get("http://www.baidu.com/"

Python simulates the browser sending post requests importrequests format request.postrequest.post(url,data,json,kwargs)#post request format request.get(url,params,kwargs)#Compared with get request, sending post request parameters are divided into forms ( x-www-form-urlencoded) json (application/json) data parameter supports dictionary format and string format. The dictionary format uses the json.dumps() method to convert the data into a legal json format string. This method requires

How to use the urllib.request.urlopen() function in Python3.x to send a GET request. In network programming, we often need to obtain data from a remote server by sending an HTTP request. In Python, we can use the urllib.request.urlopen() function in the urllib module to send an HTTP request and get the response returned by the server. This article will introduce how to use
