@@ -0,0 +1,82 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Folder;
|
||||
use App\Models\Todo;
|
||||
use App\Models\User;
|
||||
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),
|
||||
'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(),
|
||||
]);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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,
|
||||
]);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user