authentikate/database/factories/InvitationFactory.php
Javier Feliz 1fd6f03a81
Some checks failed
linter / quality (push) Successful in 3m13s
tests / ci (push) Failing after 7m37s
Started working on invites
2025-08-01 20:59:42 -04:00

61 lines
1.4 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\Invitation;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Invitation>
*/
class InvitationFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'code' => Invitation::generateCode(),
'email' => fake()->unique()->safeEmail(),
'invited_by' => User::factory(),
'expires_at' => now()->addDays(7),
'email_sent' => fake()->boolean(30),
];
}
/**
* Indicate that the invitation is expired.
*/
public function expired(): static
{
return $this->state(fn(array $attributes) => [
'expires_at' => now()->subDay(),
]);
}
/**
* Indicate that the invitation has been accepted.
*/
public function accepted(): static
{
return $this->state(fn(array $attributes) => [
'accepted_at' => now(),
'user_id' => User::factory(),
]);
}
/**
* Indicate that the email was sent.
*/
public function emailSent(): static
{
return $this->state(fn(array $attributes) => [
'email_sent' => true,
]);
}
}