我正在使用 laravel 工厂在我的数据库中生成一些假用户,但我不知道如何获取我当前正在生成的用户的用户 ID。我想获取当前用户的 id,以便可以对其进行哈希处理并将其放入 slug 中。
到目前为止,这是我的代码:
$factory->define(User::class, function (Faker $faker) {
$name = $faker->name;
$email = $faker->unique()->safeEmail;
$date_of_birth = $faker->date();
return [
'name' => $name,
'email' => $email,
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'date_of_birth' => $date_of_birth,
'slug' => (\App\User::class)->id //This is the part that doesn't work,
];
});