系统环境
OS: Mac OS X 10.10.5
安装PHP 7.1
brew install php71 --with-pear
安装Composer
curl -sS https://getcomposer.org/installer | php
mv composer.phar /usr/local/bin/composer
安装辅助工具
- PhpStorm
- MySQL Workbench (https://dev.mysql.com/downloads/workbench/)
PHP >= 7.0.0
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
新建Laravel项目
composer create-project --prefer-dist laravel/laravel librarySeating "5.5.*"
初始化
修改config/app.php中的
'url' => env('APP_URL', 'http://localhost:8000'),
'timezone' => 'PRC',
'locale' => 'zh',
同步到GitHub仓库
创建仓库
初次推送
git init
git add -A
git commit -m "first commit"
git remote add origin https://github.com/patientkitty/librarySeating.git
git push -u origin master
启动站点
在Laravel项目目录下运行
php artisan serve Laravel development server started on [http://localhost:8000](http://localhost:8000)
配置数据库链接
编辑环境变量 .env文件
创建类(Model)并关联到数据库
创建新类,存放在APP\Models目录,同时创建数据库迁移(-m)
php artisan make:model Models/Seat -m
编辑database\migrations下对应文件
public function up()
{
Schema::create('seats', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
$table->string('seat_code');
$table->string('seat_desc'->nullable());
$table->string('qrcode');
$table->string('created_by');
});
}
执行数据库迁移
php artisan migrate
填充测试数据
在app/database/seeds下创建一个名为SeatTableSeeder.php的文件,增加如下:
class SeatTableSeeder extends Seeder {
public function run()
{
for($i=1;$i<=3;$i++){
Seat::create([
'seat_code' => 'test00' . $i,
'seat_desc' => 'test seat 00' . $i,
'qrcode' => 'qrcode00' . $i,
'created_by' => 'Sam Shen',
]);
}
}
然后在DatabaseSeeder.php中增加:
$this->call('SeatTableSeeder');
刷新项目中的类文件
composer dump-autoload
之后就真正地向数据库填充数据:
php artisan db:seed
你可以查看数据库,会发现seats表中多了三条记录。
使用weui(微信界面风格)
加载weui库到public目录
NYUSH1499LP-MX:public ss9545$ git clone https://github.com/weui/weui.git
在public目录下创建css、js、font、images目录
拷贝weui.min.css到public\css目录
创建View
创建Controller
php artisan make:controller MyNewController
- 将会在/my_laravel/app/http/controllers目录下创建一个新的Controller文件
修改数据库字段类型
安装依赖
To add this dependency open the composer.json at the root of your project (in the same level as app, public etc.) and in the require section add the doctrine/dbal package like:
"require": {
"laravel/framework": "4.1.*",
"doctrine/dbal": "v2.4.2"
},
Save the file and run composer update
php artisan change_exports_date_type
in the migration file up function
Schema::table('exports', function (Blueprint $table) {
$table->date('date')->change();
});
php artisan migrate
加载基本页面元素
祖传CSS
https://pan.baidu.com/s/1JhweZQKKFEmfbWO3PjXYOg
复制到public\css目录下
祖传layouts
https://pan.baidu.com/s/18A39UvcsXMTNH0Xk4If91g
在resources\views目录下创建layouts目录,并复制文件