libra/database/factories/NotificationFactory.php

62 lines
1.5 KiB
PHP

<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Notification>
*/
class NotificationFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'user_id' => User::factory(),
'type' => fake()->randomElement(['consultation_approved', 'consultation_rejected', 'timeline_update', 'new_post']),
'data' => [
'message' => fake()->sentence(),
'action_url' => fake()->url(),
],
'read_at' => null,
'sent_at' => fake()->optional()->dateTimeBetween('-7 days', 'now'),
];
}
/**
* Create a read notification.
*/
public function read(): static
{
return $this->state(fn (array $attributes) => [
'read_at' => fake()->dateTimeBetween('-7 days', 'now'),
]);
}
/**
* Create an unread notification.
*/
public function unread(): static
{
return $this->state(fn (array $attributes) => [
'read_at' => null,
]);
}
/**
* Create a sent notification.
*/
public function sent(): static
{
return $this->state(fn (array $attributes) => [
'sent_at' => fake()->dateTimeBetween('-7 days', 'now'),
]);
}
}