52 lines
1.2 KiB
PHP
52 lines
1.2 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Database\Factories;
|
||
|
|
|
||
|
|
use App\Enums\NotificationSeverityEnum;
|
||
|
|
use App\Enums\NotificationTypeEnum;
|
||
|
|
use App\Models\Notification;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @extends Factory<Notification>
|
||
|
|
*/
|
||
|
|
class NotificationFactory extends Factory
|
||
|
|
{
|
||
|
|
protected $model = Notification::class;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @return array<string, mixed>
|
||
|
|
*/
|
||
|
|
public function definition(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'type' => fake()->randomElement(NotificationTypeEnum::cases()),
|
||
|
|
'severity' => fake()->randomElement(NotificationSeverityEnum::cases()),
|
||
|
|
'title' => fake()->sentence(3),
|
||
|
|
'message' => fake()->sentence(),
|
||
|
|
'data' => null,
|
||
|
|
'read_at' => null,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function read(): static
|
||
|
|
{
|
||
|
|
return $this->state(['read_at' => now()]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function unread(): static
|
||
|
|
{
|
||
|
|
return $this->state(['read_at' => null]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function severity(NotificationSeverityEnum $severity): static
|
||
|
|
{
|
||
|
|
return $this->state(['severity' => $severity]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function type(NotificationTypeEnum $type): static
|
||
|
|
{
|
||
|
|
return $this->state(['type' => $type]);
|
||
|
|
}
|
||
|
|
}
|