49 lines
1 KiB
PHP
49 lines
1 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace Database\Factories;
|
||
|
|
|
||
|
|
use App\Models\Planner;
|
||
|
|
use App\Models\Schedule;
|
||
|
|
use Carbon\Carbon;
|
||
|
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||
|
|
|
||
|
|
/**
|
||
|
|
* @extends Factory<Schedule>
|
||
|
|
*/
|
||
|
|
class ScheduleFactory extends Factory
|
||
|
|
{
|
||
|
|
public function definition(): array
|
||
|
|
{
|
||
|
|
return [
|
||
|
|
'planner_id' => null,
|
||
|
|
'date' => fake()->dateTimeBetween('-5 years', 'now')->format('Y-m-d'),
|
||
|
|
'is_skipped' => false,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
|
||
|
|
public function planner(Planner $planner): self
|
||
|
|
{
|
||
|
|
return $this->state(fn (array $attributes) => [
|
||
|
|
'planner_id' => $planner->id,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function date(string|Carbon $date): self
|
||
|
|
{
|
||
|
|
if ($date instanceof Carbon) {
|
||
|
|
$date = $date->format('Y-m-d');
|
||
|
|
}
|
||
|
|
|
||
|
|
return $this->state(fn (array $attributes) => [
|
||
|
|
'date' => $date,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function skipped(): self
|
||
|
|
{
|
||
|
|
return $this->state(fn (array $attributes) => [
|
||
|
|
'is_skipped' => true,
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
}
|