Files
econom/database/factories/TeamInvitationFactory.php
brusnitsyn fb2e6c58e3
Some checks failed
linter / quality (push) Has been cancelled
tests / ci (8.3) (push) Has been cancelled
tests / ci (8.4) (push) Has been cancelled
tests / ci (8.5) (push) Has been cancelled
first commit
2026-04-06 00:06:00 +09:00

63 lines
1.4 KiB
PHP

<?php
namespace Database\Factories;
use App\Enums\TeamRole;
use App\Models\Team;
use App\Models\TeamInvitation;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends Factory<TeamInvitation>
*/
class TeamInvitationFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
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),
]);
}
}