更新用户模型工厂,将用户设为已激活状态

现在,我们需要更新模型工厂,将生成的假用户和第一位用户都设为已激活状态。

database/factories/UserFactory.php

define(App\Models\User::class, function (Faker $faker) {
    $date_time = $faker->date . ' ' . $faker->time;
    static $password;

    return [
        'name' => $faker->name,
        'email' => $faker->safeEmail,
        'is_admin' => false,
        'activated' => true,
        'password' => $password ?: $password = bcrypt('secret'),
        'remember_token' => str_random(10),
        'created_at' => $date_time,
        'updated_at' => $date_time,
    ];
});

database/seeds/UsersTableSeeder.php

times(50)->make();
        User::insert($users->makeVisible(['password', 'remember_token'])->toArray());

        $user = User::find(1);
        $user->name = 'Aufree';
        $user->email = '[email protected]';
        $user->password = bcrypt('password');
        $user->is_admin = true;
        $user->activated = true;
        $user->save();
    }
}

重置并填充数据库。

$ php artisan migrate:refresh --seed

你可能感兴趣的:(更新用户模型工厂,将用户设为已激活状态)