generated from thegrind/laravel-dockerized
61 lines
1.4 KiB
PHP
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,
|
|
]);
|
|
}
|
|
}
|