管理员表设计
1.创建模型层和迁移文件
php artisan make:model Http\Model\Vuser -m
2.设计表字段
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('username',50)->default('')->comment('账号');
$table->string('truename',50)->default('')->comment('真实姓名');
$table->string('email',50)->default('')->comment('邮箱');
$table->string('phone',50)->default('')->comment('手机');
$table->string('password',250)->default('')->comment('密码');
$table->enum('sex',['男','女'])->default('男')->comment('性别');
$table->timestamps();
});
}
3.faker批量添加用户
(1.创建用户数据填充文件)
php artisan make:seeder UserSeeder
(2.数据填充文件修改)
<?php
use Illuminate\Database\Seeder;
use App\Http\Model\Vuser;
class VuserSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
//清空数据表Z
Vuser::truncate();
//添加模拟数据
factory(Vuser::class,100)->create();
//规定id=1的用户名为admin
Vuser::where('id',1)->update(['username'=>