搜索
首页php框架Laravel【laravel】blog项目实战笔记-valicator验证及分类页功能创建

总想自己一个人做一个小的项目,但是不知道怎么着手,平时上班时总是做项目中某个部分的任务,没有整体做一个项目,下面是我看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/category
public 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教程

以上是【laravel】blog项目实战笔记-valicator验证及分类页功能创建的详细内容。更多信息请关注PHP中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
任务管理工具:远程项目的优先级和跟踪进度任务管理工具:远程项目的优先级和跟踪进度May 02, 2025 am 12:25 AM

taskManagementtoolSareessential forefectiverMototeprojectManagementbyPrioritizingTaskSandTrackingProgress.1)usetoolsliketrelliketreloandasanatosetprioritieswithlabelsortags.2)

最新的Laravel版本如何提高性能?最新的Laravel版本如何提高性能?May 02, 2025 am 12:24 AM

1)itoptimizeseLizeSeloQuentModelloAdingWithlazyProxies.3)

全栈Laravel应用程序的部署策略全栈Laravel应用程序的部署策略May 02, 2025 am 12:22 AM

最佳的全栈Laravel应用部署策略包括:1.零停机部署,2.蓝绿部署,3.持续部署,4.金丝雀发布。1.零停机部署使用Envoy或Deployer自动化部署过程,确保应用在更新时保持可用。2.蓝绿部署通过维护两个环境实现无停机部署,并允许快速回滚。3.持续部署通过GitHubActions或GitLabCI/CD自动化整个部署流程。4.金丝雀发布通过Nginx配置,将新版本逐步推广给用户,确保性能优化和快速回滚。

扩展全堆栈Laravel应用程序:最佳实践和技术扩展全堆栈Laravel应用程序:最佳实践和技术May 02, 2025 am 12:22 AM

toscalealaravelApplication有效,焦点databaseSharding,缓存,负载平衡和microservices.1)实现DataBaseShardingTodistAcribedateAtaCrossmultipledataBasesForimProvesforimpRevemperformance.2)uselaravel'scachingsystemystemystemystemystemnememmemememememcachedtebachedtorcachedtobcachebab

沉默的斗争:克服分布式团队中的沟通障碍沉默的斗争:克服分布式团队中的沟通障碍May 02, 2025 am 12:20 AM

doovercomecommunicationbarriersIndistributedTeams,使用:1)VideoCallSforface-face-Faceinteraction,2)setClearresponsEtimepections,3)chooseappropropraproproprapropropriatecommunicationTools,4)CreatseateAteAteAteamCommunicationGuide和5)建立PemersonalboundariestariestopreventBreventBurniationBurnication.the

使用Laravel Blade在全栈项目中进行前端模板使用Laravel Blade在全栈项目中进行前端模板May 01, 2025 am 12:24 AM

laravelbladeenhancesfrontendtemplatinginflatinginflationll-stackprojectsbyferingCleanSyntaxandaxandpoperfelfulfeatures.1)itallowsforeasyvariableasyvariabledisplayandControlstructures.2)bladesuportsuportsuportscreatingingingingingingingingingingangingandredreingscomponents components components components,aidinginmanagingcomplexuis.3)

使用Laravel:实用教程构建全堆栈应用程序使用Laravel:实用教程构建全堆栈应用程序May 01, 2025 am 12:23 AM

laravelisidealforll-stackapplicationsduetoitselegantsyntax,complastissionecosystem和perperatefulfeatures.1)UseeloquentormForintuiveDiendbackendDatamanipulation,butavoidn 1Queryissues.2)

您使用哪种工具来保持远程角色保持连接?您使用哪种工具来保持远程角色保持连接?May 01, 2025 am 12:21 AM

forremotework,iusezoomforvideOcalls,Slackformessing,trelloforprojectmanagement,and gitgithubForCodeCollaboration.1)Zoomisreliable forlailible forlargemeetingsbuthastimelimitsonthefreeversion.2)

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

SecLists

SecLists

SecLists是最终安全测试人员的伙伴。它是一个包含各种类型列表的集合,这些列表在安全评估过程中经常使用,都在一个地方。SecLists通过方便地提供安全测试人员可能需要的所有列表,帮助提高安全测试的效率和生产力。列表类型包括用户名、密码、URL、模糊测试有效载荷、敏感数据模式、Web shell等等。测试人员只需将此存储库拉到新的测试机上,他就可以访问到所需的每种类型的列表。

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

Dreamweaver Mac版

Dreamweaver Mac版

视觉化网页开发工具