laravel之个人学习文档
Artisan 命令
命令 | 说明 |
php artisan key:generate | 生成 App Key |
php artisan make:controller | 生成控制器 |
php artisan make:model | 生成模型 |
php artisan make:policy | 生成授权策略 |
php artisan make:middleware | 生成中间件 |
php artisan make:seeder | 生成 Seeder 文件 |
php artisan migrate | 执行迁移 |
php artisan migrate:rollback | 回滚迁移 |
php artisan migrate:refresh | 重置数据库 |
php artisan db:seed | 填充数据库 |
php artisan tinker | 进入 tinker 环境 |
php artisan route:list | 查看路由列表 |
php artisan list | 查看所有artisan命令列表 |
在blade模板打印变量信息
{{ dump('test') }}
# 生成资源控制器命令
php artisan make:controller PhotoController --resource
# 生成 console 命令
php artisan make:console consoleName
#如果需要指定路径 例如 放在Web目录下
php artisan make:console Web\consoleName
# console 命令执行
php artisan $signature
Laravel 数据库查询篇
场景:查询某一字段内容的集合,例:查询性别为男性的所有姓名
$users = Users::where('sex', 1)->pluck('username');
得到的结果为:
array(
'1' => '张三'
'2' => '李四'
'3' => '王五'
'4' => '李小六'
'5' => '赵五'
)
Laravel分页方法:
$tests->count() //当前页显示个数
$tests->currentPage() //当前页数
$tests->hasMorePages() //判断是不是还有更多页,比如最后一页她就不显示,不然就显示1
$tests->lastPage() //最后一页,也是总页数(在 simplePaginate 中无法使用)
$tests->nextPageUrl() //下一页的连接
$tests->perPage() //定义的每页个数
$tests->previousPageUrl() //上一页连接
$tests->total() //总数据量,就是总记录数(在 simplePaginate 中无法使用)
$tests->url($page) //$page是你想跳转到的页数,你也可以同时用获取总页数,然后用url定义到最后一页