*/ class TeamInvitationFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'team_id' => Team::factory(), 'email' => fake()->unique()->safeEmail(), 'role' => TeamRole::Member, 'invited_by' => User::factory(), 'expires_at' => null, 'accepted_at' => null, ]; } /** * Indicate that the invitation has been accepted. */ public function accepted(): static { return $this->state(fn (array $attributes) => [ 'accepted_at' => now(), ]); } /** * Indicate that the invitation has expired. */ public function expired(): static { return $this->state(fn (array $attributes) => [ 'expires_at' => now()->subDay(), ]); } /** * Indicate that the invitation expires in the given time. */ public function expiresIn(int $value, string $unit = 'days'): static { return $this->state(fn (array $attributes) => [ 'expires_at' => now()->add($unit, $value), ]); } }