总想自己一个人做一个小的项目,但是不知道怎么着手,平时上班时总是做项目中某个部分的任务,没有整体做一个项目,下面是我看php中文网的视频整理的笔记,供大家参考。这是在Windows环境下做的blog实战项目,以下文章是项目的一部分,我一节一节分享的,要想看更多关注我,我会持续更新。
一、后台超级管理员密码的修改以及validation的验证
1)首先分配个路由
2)写个方法
if($input=Input::all()){$rules = ['password'=>'required'];}$validator= Validator::make($input,$rules);
Validator类的引用
use Illuminate\Support\Facades\Validator;if($validator->passes()){echo 'yes';}else{echo 'no';}}
3)怎么知道validator里到底是什么错误
$validator->errors()->all();
位置写法
if($input=Input::all()){$rules = ['password'=>'required'];$validator= Validator::make($input,$rules);
Validator类的引用
use Illuminate\Support\Facades\Validator;if($validator->passes()){echo 'yes';}else{dd( $validator->errors()->all());}}
报错的错误信息
array:1 [▼ 0 => "The password field is required."]
3)因为错误信息是英文,怎么翻译中文
$validator= Validator::make($input,$rules,$massege);
make还有带三个参数massege
if($input=Input::all()){$rules = ['password'=>'required'];$message=['password.required'=>'新密码不能为空'];$validator= Validator::make($input,$rules,$message);
Validator类的引用
use Illuminate\Support\Facades\Validator;if($validator->passes()){echo 'yes';}else{dd( $validator->errors()->all());}}
4)密码6-20位之间
$rules = ['password'=>'required|between:6,20'];array:1 [▼ 0 => "The password must be between 6 and 20 characters."]$message=['password.required'=>'新密码不能为空','password.between'=>'新密码必须在6到20位之间'];
5)新密码和旧密码要匹配confirmed
改页面的确认密码:
name:password_confrimation$rules = ['password'=>'required|between:6,20|confirmed'];array:2 [▼ 0 => "新密码必须在6位到20位之间" 1 => "The password confirmation does not match."]$message=['password.required'=>'新密码不能为空','password.between'=>'新密码必须在6到20位之间''password.confirmed'=>'新密码和确认密码不一致'];array:1 [▼ 0 => "新密码和确认密码不一致"]
二、后台文章分类列表页模板导入及基本展示
1)创建资源控制器
php artisan make:controller Controllers/CategroyController
2)创建资源路由
Route::resource('categroy', 'CategroyController');
3)查看一下资源路由
php artisan route:list
4)根据上面的表创建相应的方法
GET home/category 全部分类列表
public function index(){}
GET home/category/create 添加分类
public function create(){}
PUT home/category/{category} 更新分类
public function update(){}
GET home/category/{category} 显示单个分类信息
public function show(){}
DELETE home/category/{category} 删除单个分类
public function destroy(){}
GET home/category/{category}/edit 编辑分类
public function edit(){} POST home/categorypublic function store(){}
5)获取全部分类列表,和数据库对接就应该获取model
php artisan make:model Models/CategroyModel
在模型的类里 初始化信息
protected $table = 'blog_categroy';protected $primaryKey = 'cate_id';public $timestamps ='false';
6)在在控制器的方法里获取数据
$categroy = CategroyModel::all();dd($categroy);
7)分配模板
return view('home/categroy/index'); //home文件夹里categroy文件夹的index模板
8)把数据分配到模板中
return view('home/categroy/index')->with('data',$categroy);
9)在模板里读数据
@foreach($data as $v){{$v->cate_name}}@endforeach
以上步骤是我学习的笔记,我把要操作的步骤或重点的记了下来,如果哪有不懂可以留言。谢谢大家支持。希望能为小白提供帮助,如果想看更多blog项目信息,关注我,下一篇继续分享。
相关推荐:《laravel教程》