year = is_numeric($year) ? (int)$year : null; } /** * Execute the job. * * @return void */ public function handle() { $targetYear = $this->year ?? now()->year + 1; $url = "https://calendrier.api.gouv.fr/jours-feries/metropole/{$targetYear}.json"; $response = Http::get($url); if ($response->successful()) { $publicHolidays = $response->json(); $magasins = Magasin::with('collecteExceptions')->get(); foreach ($magasins as $magasin) { foreach ($publicHolidays as $date => $holidayName) { $existingException = $magasin->collecteExceptions()->where('date', $date)->first(); if (!$existingException) { $magasin->collecteExceptions()->create([ 'date' => $date, 'comment' => $holidayName, 'type' => ExceptionDayType::ferie() ]); } } } } } }