新建一个数据库;
配置database.php里面的数据库信息;
生成模型,顺带生成迁移表;
#前面可以添加目录
PS D:\phpStudy\WWW\laravel54cn> php artisan make:model Home/Article -m
Model created successfully.
Created Migration: 2017_08_04_093936_create_articles_table
#默认创建在`D:\phpStudy\WWW\laravel54cn\app\Test.php`
PS D:\phpStudy\WWW\laravel54cn> php artisan make:model Test -m
Model created successfully.
Created Migration: 2017_08_04_094138_create_tests_table
生成的数据表位置及字段:
D:\phpStudy\WWW\laravel54cn\database\migrations\2017_08_04_094138_create_tests_table.php
public function up()
{
Schema::create('tests', function (Blueprint $table) {
$table->increments('id');
$table->timestamps();
});
}
这里面可以添加需要的自定义的字段,设置类型多多:
D:\phpStudy\WWW\bcc_service\vendor\laravel\framework\src\Illuminate\Database\Schema\Blueprint.php
public function up() {
Schema::create('users', function (Blueprint $table) {
$table->increments('id')->comment('自增id,为主键');
$table->string('name',20)->unique()->comment('用户名');
$table->string('email',50)->unique()->comment('用户邮箱');
$table->string('password')->comment('密码');
#登陆的时候可以选择记住
$table->rememberToken()->comment('记住我');
#设置联合索引
$table->index(['queue', 'reserved_at']);
#会生成created_at和updated_at两个字段
$table->timestamps();
#以下是数据表备注
$table->comment('这里可以写表备注');
});
}
运行迁移命令;
php artisan migrate
填充数据。