*/ class OrganizationFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { return [ 'name' => fake()->unique()->company(), 'personal_workspace' => false, 'lifetime_access' => false, ]; } /** * Indicate that the organization is a single user's personal workspace. */ public function personal(): static { return $this->state(fn (array $attributes) => [ 'personal_workspace' => true, ]); } /** * Give the organization perpetual access, as granted to accounts that * predate subscriptions. */ public function withLifetimeAccess(): static { return $this->state(fn (array $attributes) => [ 'lifetime_access' => true, ]); } /** * Add the given user to the organization with the given role. */ public function withMember(User $user, OrganizationRole $role = OrganizationRole::Owner): static { return $this->afterCreating(function (Organization $organization) use ($user, $role): void { $organization->users()->attach($user, ['role' => $role->value]); }); } }