factory()->create() and rely on that shape still pass. The * ->realistic() state below is what the seeder uses for * demo/dev data — anchored dates, expected end, and sometimes * completed_at populated so the calendar and list views show a * plausible mix. * * @return array */ public function definition() { $maintenanceType = MaintenanceType::factory()->create(); return [ // Set location_id to rtd_location_id on the generated asset so // seeded maintenance rows point at assets with a real location, // matching what snipeit:sync-asset-locations would have set. 'asset_id' => Asset::factory()->laptopZenbook()->afterMaking(function (Asset $asset) { if ($asset->location_id === null) { $asset->location_id = $asset->rtd_location_id; } }), 'supplier_id' => Supplier::factory(), 'maintenance_type_id' => $maintenanceType->id, 'asset_maintenance_type' => $maintenanceType->name, 'name' => $this->faker->randomElement(self::NAMES), 'start_date' => $this->faker->dateTime()->format('Y-m-d H:i:s'), 'is_warranty' => $this->faker->boolean(), 'notes' => $this->faker->paragraph(), 'url' => $this->faker->url(), 'cost' => $this->faker->randomFloat(2, 5, 500), 'created_by' => User::factory()->superuser(), 'image' => $this->faker->numberBetween(1, 11).'.png', ]; } /** * Seeder-friendly state that produces a maintenance with * start_date anchored around today, an expected_completion_date * a few days out, and a ~40% chance of already being completed * (for past-start rows only). Produces a plausible mix on the * calendar / list views so demo installs don't render as * "everything from 1974". */ public function realistic(): static { return $this->state(function () { $startDate = $this->faker->dateTimeBetween('-6 months', '+3 months'); $startCarbon = \Carbon\Carbon::instance($startDate); $expectedEnd = (clone $startCarbon)->addDays($this->faker->numberBetween(1, 21)); $isCompletable = $startCarbon->isPast() && $this->faker->boolean(40); $completedAt = $isCompletable ? $this->faker->dateTimeBetween($startCarbon, min($expectedEnd, \Carbon\Carbon::now())) : null; return [ 'start_date' => $startCarbon->format('Y-m-d H:i:s'), 'expected_completion_date' => $expectedEnd->format('Y-m-d H:i:s'), 'completed_at' => $completedAt?->format('Y-m-d H:i:s'), ]; }); } }