建立迁移文件
php artisan make:migration create_member_table
Schema::create('member', function (Blueprint $table) { $table->increments('id'); $table->string('username',20)->notNull(); $table->string('password')->notNull(); $table->enum('gender',[1,2,3])->notnull()->default('1'); $table->string('mobile',11); $table->string('email',40); $table->string('avatar'); $table->timestamps(); $table->RememberToken(); $table->enum('type',[1,2])->notnull()->default('1'); $table->enum('status',[1,2])->notnull()->default('1'); });
执行迁移文件:
#php artisan migrate
建立假数据
使用faker代码依赖生成测试数据500条
①创建填充器文件
#php artisan make:seeder MemberTableSeeder
②编写填充器代码,使用faker生成假数据
public function run() { $faker = Faker\Factory::create("zh_CN"); for($i=0;$i<500;$i++) { $data[] = [ 'username' => $faker->username, 'password' => bcrypt("123456"), 'gender' => mt_rand(1, 3), 'mobile' => $faker->phoneNumber, 'email' => $faker -> email, 'avatar' => '/statics/avatar.jpg', 'created_at' => date('y-m-d H:i:s', time()), 'type' => mt_rand(1, 2), 'status' => mt_rand(1, 2) ]; } DB::table('member')->insert($data); }
③执行填充器文件
#php artisan db:seed --class=MemberTableSeeder