authentikate/database/factories/InvitationFactory.php
Javier Feliz 292ec10b48
Some checks failed
linter / quality (push) Successful in 4m37s
tests / ci (push) Failing after 8m58s
Invitation system test
2025-08-02 14:11:43 -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' => fake()->unique()->regexify('[A-Za-z0-9]{50}'),
'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,
]);
}
}