*/ class UserFactory extends Factory { /** * The current password being used by the factory. */ protected static ?string $password; protected static ?int $role; /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'first_name' => fake()->firstName(), 'last_name' => fake()->lastName(), 'display_name' => fake()->name(), 'username' => fake()->unique()->userName(), 'email' => fake()->unique()->safeEmail(), 'email_verified_at' => fake()->dateTime(), 'phone' => fake()->phoneNumber(), 'password' => static::$password ??= Hash::make('password'), 'two_factor_secret' => null, 'two_factor_recovery_codes' => null, 'remember_token' => Str::random(10), 'profile_photo_path' => null, 'current_team_id' => null, 'organization_id' => null, 'department_id' => null, 'is_active' => fake()->boolean(), ]; } /** * Indicate that the model's email address should be unverified. */ public function unverified(): static { return $this->state(fn (array $attributes) => [ 'email_verified_at' => null, ]); } /** * Indicate that the user should have a personal team. */ public function withPersonalTeam(?callable $callback = null): static { if (! Features::hasTeamFeatures()) { return $this->state([]); } return $this->has( Team::factory() ->state(fn (array $attributes, User $user) => [ 'name' => $user->name . '\'s Team', 'user_id' => $user->id, 'personal_team' => true, ]) ->when(is_callable($callback), $callback), 'ownedTeams' ); } }