In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-07 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail the example analysis of valicator verification and classification page function creation of blog project in laravel, the editor thinks it is very practical, so share it with you for reference, hope that you can get something after reading this article.
First, the password modification of the background super administrator and the verification of validation
1) assign a route first
2) write a method
If ($input=Input::all ()) {$rules = ['password'= >' required'];} $validator= Validator::make ($input,$rules)
References to the Validator class
Use Illuminate\ Support\ Facades\ Validator;if ($validator- > passes ()) {echo 'yes';} else {echo' no';}}
3) how to know what is wrong in validator
$validator- > errors ()-> all ()
Position writing method
If ($input=Input::all ()) {$rules = ['password'= >' required']; $validator= Validator::make ($input,$rules)
References to the Validator class
Use Illuminate\ Support\ Facades\ Validator;if ($validator- > passes ()) {echo 'yes';} else {dd ($validator- > errors ()-> all ());}}
An error message.
Array:1 [▼ 0 = > "The password field is required."]
3) because the error message is English, how to translate it into Chinese
$validator= Validator::make ($input,$rules,$massege)
Make also has massege with three parameters
If ($input=Input::all ()) {$rules = ['password'= >' required']; $message= ['password.required'= >' New password cannot be empty']; $validator= Validator::make ($input,$rules,$message)
References to the Validator class
Use Illuminate\ Support\ Facades\ Validator;if ($validator- > passes ()) {echo 'yes';} else {dd ($validator- > errors ()-> all ());}}
4) between 6 and 20 digits of the password
$rules = ['password'= >' required | between:6,20']; array:1 [▼ 0 = > "The password must be between 6 and 20 characters."] $message= ['password.required'= >' New password cannot be empty', 'password.between'= >' New password must be between 6 and 20 digits']
5) the new password and the old password should match confirmed
Change the confirmation password of the page:
Name:password_confrimation$rules = ['password'= >' required | between:6,20 | confirmed']; array:2 [▼ 0 = > "New password must be between 6 and 20 digits" 1 = > "The password confirmation does not match."] $message= ['password.required'= >' New password cannot be empty', 'password.between'= >' New password must be between 6 and 20 digits' password.confirmed'= > 'New password and confirmation password are inconsistent'] Array:1 [▼ 0 = > "New password and confirmation password do not match"]
Second, background article classification list page template import and basic display
1) create a resource controller
Php artisan make:controller Controllers/CategroyController
2) create a resource route
Route::resource ('categroy',' CategroyController')
3) check the resource routing
Php artisan route:list
4) create the corresponding method according to the above table
GET home/category all Category list
Public function index () {}
GET home/category/create add categories
Public function create () {}
PUT home/category/ {category} update classification
Public function update () {}
GET home/category/ {category} displays individual classification information
Public function show () {}
DELETE home/category/ {category} Delete a single category
Public function destroy () {}
GET home/category/ {category} / edit Edit Category
Public function edit () {} POST home/categorypublic function store () {}
5) get the list of all categories. If you interface with the database, you should get model.
Php artisan make:model Models/CategroyModel
Initialize information in the class of the model
Protected $table = 'blog_categroy';protected $primaryKey =' cate_id';public $timestamps = 'false'
6) get the data in the controller method
$categroy = CategroyModel::all (); dd ($categroy)
7) assign template
Return view ('home/categroy/index'); / / the index template of the categroy folder in the home folder
8) assign the data to the template
Return view ('home/categroy/index')-> with (' data',$categroy)
9) read the data in the template
@ foreach ($data as $v) {{$v-> cate_name}} @ endforeach on "valicator validation of blog projects in laravel and sample analysis of category page creation" is the end of this article. I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.