Laravel framework automatic verification (data verification)

Automatic verification
Automatic verification: can verify the data submitted by the user on the back end.
We use cases to achieve automatic verification of data in the background.
Example: Use test 8 form page, submit to test9 route.
1. Add route in web.php

route::get(‘test8’,‘KongyooController@test8’);
route::get(‘test9’,‘KongyooController@test9’)->name(‘t9’);

2. Add a method to the controller

public function test8 () {
return view ('test8');
}
public function test9 (Request $ request) {
// 1, automatic verification
// 2, get data and write data
// 3, do according to the written data Come up with different responses
// write verification logic
t h i s > v a l i d a t e ( this->validate( request,[
‘name’=>‘required|min:2|max:6’,
‘age’=>‘required|min:0|max:100|integer’,
‘email’=>‘required|email’
]);
}

validate method: Receive an HTTP request input data and verification rules. If the verification rules are passed, the code will continue to be executed;
'title' => the corresponding rules for verification.
Commonly used verification rules:

Rule verification data description

required Required
email E-mail format
in: A, B Data limit range is A and B
integer integer
alpha English letters a ~ z
alpha_num English letters az and numbers 09
min: value minimum value, when it is integer field, it is expressed as The minimum value of the value, when expressed as a string, it is expressed as the length of the string
man: value maximum value, when it is an integer field, it is expressed as the maximum value of the value, when it is expressed as a string, it is expressed as Length
array array data
numeric numeric data
string string data
before before the specified date
after after the specified date
between: min, max in the specified range
date is correct time
date_form: format date format
ip IP address
url URL
3, in the new The content of the view file ky3.blade.php is

Document Name:
Age:
Email:
{{csrf_field ()}}
Published 38 original articles · praised 0 · visits 864

Guess you like

Origin blog.csdn.net/niudehao1/article/details/105598748