BlueXIII's Blog

热爱技术,持续学习

0%

Laravel学习笔记

资料

安装Laravel命令行

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# 安装laravel安装器
composer global require laravel/installer
laravel --version
Laravel Installer 4.2.9

# 查看composer配置路径
composer global about
/Users/bluexiii/.composer/vendor/bin

# 将composer的bin目录加入PATH
vi ~/.zshrc
export PATH="/Users/bluexiii/.composer/vendor/bin:$PATH"

# 新建laravel工程
laravel new blog

# 测试启动
php artisan serve

工程初始化

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# 编辑.env
cp .env.example .env
vi .env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=agric
DB_USERNAME=agric
DB_PASSWORD=sw123

MONGO_HOST=127.0.0.1
MONGO_PORT=27017
MONGO_DATABASE=agric
MONGO_USERNAME=agric
MONGO_PASSWORD=sw123

# 在.env中生成KEY
php artisan key:generate

# 建表
php artisan migrate

# 导入基础数据
php artisan db:seed

# 启动Server
php artisan serve

Artisan命令行用法

1
2
3
4
5
6
7
8
9
10
# 查看命令列表
php artisan list

# 查看帮助
php artisan help migrate

# 其它
php artisan config:cache # 生成配置缓存(开发环境会造成.env修改无效)
php artisan config:clear # 取消配置缓存
php artisan passport:keys # 生成Oauth密钥对

日志打印SQL

1
2
3
4
5
6
7
8
9
10
public function boot() {
Schema::defaultStringLength(191);
DB::listen(function($query) {
Log::info(
$query->sql,
$query->bindings,
$query->time
);
});
}

本地仓库

vi composer.json

1
2
3
4
5
6
7
"require": {
"harris/sw_common": "dev-master",
},
"repositories": [{
"type": "path",
"url": "/Users/bluexiii/Documents/code/evayinfo/idatasky/harris-sw_common"
}]