@extend继承模版
@include包含模版
@yield(参数)
模型:
模型名:Post->posts(表名)
tinker 测试模型
设置时序:config\app.php中的timezone 设置为Asia/Shanghai
路由中{{post}}为模型绑定 在controller中show(模型,$post)
查询:
\App\Post::where('title','=','1111')->first(); //只查询一个,返回数组
如果是get(),则返回Collection对象,返回所有查询到的数据
>>> \App\Post::where('title','=','1111')->get();
=> Illuminate\Database\Eloquent\Collection {#712
all: [
App\Post {#717
id: 2,
title: "1111",
content: "222",
user_id: 0,
created_at: "2018-07-25 22:21:57",
updated_at: "2018-07-25 22:21:57",
},
时间格式:http://carbon.nesbot.com/docs/
数据填充:https://github.com/fzaninotto/Faker/
在database文件夹下面的factory.php中,代码如下
$factory->define(App\Post::class,function (Faker\Generator $faker) {
return [
'title' => $faker->sentence(6), //句子
'content'=>$faker->paragraph(10), //段落
];
});
执行数据填充
factory(App\Post::class,20(插入的数量))->create()
分页:paginate(5);表示一个页面显示5个
在分页逻辑中加入 {{$posts->links()}}
字符截断:
{{str_limit($post->content,100,'...')}}
传递:
dd对非常大的数据进行美化
csrf保护:传递token字段,作为保护 ,在网页插入如下的token提交表单代码
<input type="hidden" name="_token" value="{{csrf_token()}}">
或者{{csrf_field()}}
获取参数
如果传入模型的是数组,则需要设置模型可以注入的字段
protected $guarded = []; //如果为空,则可以传入所有数组
protected $fillable = ['title','content'] //可以注入的数组
跳转:redirect("/posts");
验证:
$this->validate(\request()->all(),[
'title'=>'required|string|max:100|min:5',
'content'=>'required|string|min:10',
]);
中文验证:config/app.php中的 'locale'=>'en'改为你的文件夹
富文本编辑器