*/ class PlannedTaskFactory extends Factory { /** * Define the model's default state. * * @return array */ public function definition(): array { $plannedDate = fake()->dateTimeBetween('-1 week', '+3 weeks'); return [ 'planned_date' => $plannedDate, 'execution_date' => fake()->optional()->dateTimeBetween($plannedDate, '+2 months'), 'type' => 'treatment', 'note' => fake()->optional()->sentence(10), 'taskable_type' => Treatment::class, 'taskable_id' => Treatment::factory(), ]; } /** * Target a specific treatment. */ public function forTreatment(Treatment $treatment): static { return $this->state(fn (array $attributes) => [ 'type' => 'treatment', 'taskable_type' => Treatment::class, 'taskable_id' => $treatment->getKey(), ]); } /** * Target a specific harvest. */ public function forHarvest(Harvest $harvest): static { return $this->state(fn (array $attributes) => [ 'type' => 'harvest', 'taskable_type' => Harvest::class, 'taskable_id' => $harvest->getKey(), ]); } }