95 lines
2.1 KiB
PHP
95 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace Database\Factories;
|
|
|
|
use App\Models\Folder;
|
|
use App\Models\Todo;
|
|
use App\Models\User;
|
|
use App\TodoStatus;
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
|
|
|
/**
|
|
* @extends Factory<Todo>
|
|
*/
|
|
class TodoFactory extends Factory
|
|
{
|
|
/**
|
|
* Define the model's default state.
|
|
*
|
|
* @return array<string, mixed>
|
|
*/
|
|
public function definition(): array
|
|
{
|
|
return [
|
|
'user_id' => User::factory(),
|
|
'folder_id' => Folder::factory(),
|
|
'description' => fake()->sentence(6),
|
|
'status' => TodoStatus::Open,
|
|
'due_date' => today()->addDays(5),
|
|
'completed_at' => null,
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Indicate that the todo has no due date.
|
|
*/
|
|
public function noDueDate(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'due_date' => null,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the todo has notes.
|
|
*/
|
|
public function withNotes(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'notes' => fake()->paragraph(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the todo has been completed.
|
|
*/
|
|
public function completed(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'completed_at' => now(),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Apply the given status to the todo.
|
|
*/
|
|
public function withStatus(TodoStatus $status): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'status' => $status,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the todo is overdue.
|
|
*/
|
|
public function overdue(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'due_date' => today()->subDays(3),
|
|
'completed_at' => null,
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* Indicate that the todo is due today and still open.
|
|
*/
|
|
public function dueToday(): static
|
|
{
|
|
return $this->state(fn (array $attributes) => [
|
|
'due_date' => today(),
|
|
'completed_at' => null,
|
|
]);
|
|
}
|
|
}
|