57 lines
1.4 KiB
PHP
57 lines
1.4 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Enums\InviteStatus;
|
|
use App\Enums\WorkspaceRole;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
use Illuminate\Support\Str;
|
|
|
|
/**
|
|
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\WorkspaceInvite>
|
|
*/
|
|
class WorkspaceInviteFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'workspace_id' => Workspace::factory(),
|
|
'invited_by' => User::factory(),
|
|
'email' => fake()->unique()->safeEmail(),
|
|
'token' => Str::random(64),
|
|
'role' => WorkspaceRole::Member,
|
|
'status' => InviteStatus::Pending,
|
|
'expires_at' => now()->addDays(7),
|
|
];
|
|
}
|
|
|
|
public function expired(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'expires_at' => now()->subDay(),
|
|
'status' => InviteStatus::Expired,
|
|
]);
|
|
}
|
|
|
|
public function accepted(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'status' => InviteStatus::Accepted,
|
|
'accepted_at' => now(),
|
|
]);
|
|
}
|
|
|
|
public function cancelled(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'status' => InviteStatus::Cancelled,
|
|
]);
|
|
}
|
|
}
|