*/ final class UserFactory extends Factory { protected static ?string $password; /** @return array */ public function definition(): array { return [ 'first_name' => fake('nl_NL')->firstName(), 'last_name' => fake('nl_NL')->lastName(), 'date_of_birth' => fake()->dateTimeBetween('-50 years', '-18 years')->format('Y-m-d'), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => now(), 'password' => self::$password ??= Hash::make('password'), 'timezone' => 'Europe/Amsterdam', 'locale' => 'nl', 'remember_token' => Str::random(10), ]; } public function unverified(): static { return $this->state(fn () => ['email_verified_at' => null]); } /** * Volunteer-only user — has a Person record (portal context), * no Spatie role, no organisation membership. */ public function volunteer(): static { return $this->afterCreating(function (User $user): void { Person::factory()->create(['user_id' => $user->id]); }); } /** * Organizer-only user — attached to a fresh Organisation as `org_admin`, * no Person record, no Spatie role. */ public function orgAdmin(): static { return $this->afterCreating(function (User $user): void { $organisation = Organisation::factory()->create(); $organisation->users()->attach($user, ['role' => 'org_admin']); }); } /** * Multi-role user — has both a Person record AND organisation membership. */ public function volunteerAndOrganizer(): static { return $this->volunteer()->orgAdmin(); } /** * Platform admin — Spatie super_admin role. No org/person attachments * by default (mirrors the production case where super_admins live above * the org tree). */ public function superAdmin(): static { return $this->afterCreating(function (User $user): void { $user->assignRole('super_admin'); }); } }