*/ class UserFactory extends Factory { /** * The current password being used by the factory. */ protected static ?string $password; /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'login' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), 'pass' => static::$password ??= Hash::make('password'), 'remember_token' => Str::random(10), 'type' => $this->faker->randomElement(['A', 'H', 'P']), ]; } /** * Indicate that the model's email address should be unverified. */ public function unverified(): static { return $this->state(fn (array $attributes) => [ 'email_verified_at' => null, ]); } public function admin(): Factory { return $this->state(function (array $attributes) { return [ 'type' => 'A', ]; })->afterCreating(function ($user) { $user->assignRole('admin'); }); } /** * Define dj user */ public function dj(): Factory { return $this->state(function (array $attributes) { return [ 'type' => 'H', ]; })->afterCreating(function ($user) { $user->assignRole('dj'); }); } /** * Define editor user */ public function editor(): Factory { return $this->state(function (array $attributes) { return [ 'type' => 'P', ]; })->afterCreating(function ($user) { $user->assignRole('editor'); }); } }