*/ class UserFactory extends Factory { protected static ?string $password; public function definition(): array { $firstName = fake()->firstName(); $lastName = fake()->lastName(); return [ 'first_name' => $firstName, 'last_name' => $lastName, 'name' => "{$firstName} {$lastName}", 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => static::$password ??= Hash::make('password'), 'remember_token' => Str::random(10), 'job_title' => fake()->jobTitle(), 'department' => fake()->randomElement(['Verwaltung', 'Pflege', 'IT', 'Personal', 'Buchhaltung', 'Technik']), 'location' => fake()->city(), 'phone' => fake()->phoneNumber(), 'is_active' => true, ]; } public function admin(): static { return $this->afterCreating(fn (User $user) => $user->roles()->attach(Role::administration()->id, ['source' => 'manual', 'created_at' => now()])); } /** * @param list $roles */ public function withRoles(array $roles): static { return $this->afterCreating(fn (User $user) => $user->syncManualRoles(array_map(fn ($r) => $r instanceof Role ? $r->id : $r, $roles))); } public function inactive(): static { return $this->state(fn () => ['is_active' => false]); } public function unverified(): static { return $this->state(fn () => ['email_verified_at' => null]); } }