@@ -0,0 +1,59 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Organization;
|
||||
use App\Models\User;
|
||||
use App\OrganizationRole;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends Factory<Organization>
|
||||
*/
|
||||
class OrganizationFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
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]);
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user