*/ class UserFactory extends Factory { /** * The current password being used by the factory. */ protected static ?string $password = null; /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'name' => fake()->name(), 'email' => fake()->unique()->safeEmail(), 'password' => static::$password ??= Hash::make('password'), 'token' => bin2hex(random_bytes(32)), 'remember_token' => Str::random(10), ]; } /** * Indicate that the user is an admin. */ public function admin(): static { return $this->state(fn (array $attributes) => [ 'name' => 'Admin User', 'email' => 'admin@example.com', ]); } /** * Indicate that the user is a test user. */ public function test(): static { return $this->state(fn (array $attributes) => [ 'name' => 'Test User', 'email' => 'test@example.com', ]); } }