用户认证
生成:php artisan make:auth
Authentication scaffolding generatedsuccessfully.
1.路由web.php
Auth::routes();
所指路径是指:vendor/laravel/framework/Illuminate/src/routing/router.php 里面auth方法
2.数据迁移
php artisan migrate
Migration table created successfully.
Migrating:2014_10_12_000000_create_users_table
Migrated: 2014_10_12_000000_create_users_table
Migrating:2014_10_12_100000_create_password_resets_table
Migrated: 2014_10_12_100000_create_password_resets_table
Migrating:2016_09_13_060102_create_students_table
Migrated: 2016_09_13_060102_create_students_table
数据迁移
1.生成迁移文件
例如新建立students表
a. 新建一个表的迁移文件
php artisanmake:migration create_students_table –create=students
--table和—create参数可以用来指定数据表的名称,以及迁移文件是否要建立新的数据表
b. 生成模型的同时生成迁移文件
php artisan make:modelStudent –m
查看地址:database/migrations
完善up方法
public function up()
{
Schema::create('students', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
//unsigned 非负数
$table->integer('age')->unsigned()->default(0);
$table->integer('sex')->unsigned()->default(10);
$table->integer('created_at')->default(0);
$table->integer('updated_at')->default(0);
});
}
2. 执行迁移文件生成表
php artisan migrate
数据填充
1. 创建一个填充文件,并完善
Php artisan make:seederStudentTableSeeder
Seeder created successfully.
查看地址:database/seeds
完善的run()
Publice function run () {
DB::table(‘students’)->inset([
[‘name’=>111,‘age’=>18],
[‘name’=>111,‘age’=>18]
]);
}
2. 我们需要在 DatabaseSeeder.php 中增加两行,让Laravel在seed的时候会带上我们新增的seed文件。
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
*Run the database seeds.
*
*@return void
*/
public function run()
{
$this->call('StudentTableSeeder');
}
}
批量执行填充文件
php artisan db:seed
3. 执行单个填充文件
php artisan db:seed --class=StudentTableSeeder