技术饭
Laravel框架重要知识整理
1、路由绑定模型

2、Laravel tinker:所有 Laravel 应用都包含了 Tinker,一个基于 PsySH 包提供支持的 REPL。 Tinker 让你可以在命令行中与你整个的 Laravel 应用进行交互,包括 Eloquent ORM、任务、事件等等。运行 Artisan 命令 tinker 进入 Tinker 环境:

3、时间格式化类:http://carbon.nesbot.com/docs/
4、数据填充类:https://packagist.org/packages/fzaninotto/faker 或者 https://github.com/fzaninotto/Faker
5、tinker批量插入数据
1)、配置database/factories下的UserFactory.php

2)、tinker执行 factory() 方法批量新增,create()方法改成make()则只显示不新增

6、模板其他:时间格式化方法、内容模板解析{!! str_limit($data->content) !!}

7、文件上传,为了使文件能通过网络访问,你需要创建 public/storage 到storage/app/public 的符号链接:php artisan storage:link

8、Laravel的api查询:https://laravel.com/api/5.6/
9、Auth权限
1)、登陆

2)、退出

3)、验证是否登陆

4)、policy类验证是否有权限
4-1)、AuthProvider添加门卫类

4-2)、PostPolicy门卫类验证规则

4-3)、控制器验证门卫权限

4-4)、模板控制门卫权限

10、关联模型
10-1)、模型关联


10-2)、with预加载


10-3)、模型关联在模板中的使用



10-4)、关联新增与删除

10-5)、withPivot获取关联字段

10-6)、其他


11、视图合成器以及scope语句组装sql
11-1)、app/Providers/AppServiceProvider 作为服务启动项可执行程序之前的代码,例如全局执行视图合成器

11-2)、scope查询语句


11-3)、全局scope

11-4)、不使用全局scope

12、elasticsearch搜索引擎:http://www.elastic.co/cn/ 或者 https://github.com/medcl/elasticsearch-analysis-ik
12-1)、安装elasticsearch中文集成环境
1)、先安装jdk8+:https://blog.csdn.net/yx1214442120/article/details/55098380
2)、下载集成包:https://github.com/medcl/elasticsearch-rtf
12-2)、安装laravel搜索驱动
1)、安装laravel/scout扩展:https://laravel-china.org/docs/laravel/5.6/scout

2)、安装scout的es驱动:https://github.com/ErickTamayo/laravel-scout-elastic

13、资源路由Route::resource('路由别名','绑定控制','参数')
13-1)、路由规则已经匹配的uri


14、Gate门卫权限判断
14-1)、在AuthServiceProvider中定义Gate

14-2)、路由实现

14-3)、模板的实现

文明上网理性发言!