firstOrFail()->value; $exceptionsCollecte = CollecteException::orderBy('date')->get(); return view('bo.creneaux.settings', compact('timeslotSettings', 'plage_days', 'exceptionsCollecte')); } public function updateSettings(Request $request) { $plage = $request->plage; $plage_days = $request->plage_days; foreach($plage as $index => $day) { $setting = TimeslotSetting::where('day_index', ''.$index)->firstOrFail(); $setting->morning_start = $day['morning_start']; $setting->morning_end = $day['morning_end']; $setting->afternoon_start = $day['afternoon_start']; $setting->afternoon_end = $day['afternoon_end']; $setting->interval = $day['interval']; $setting->max_orders_per_interval = $day['max_orders_per_interval']; $setting->min_order_preparation = $day['min_order_preparation']; $setting->save(); } $order_withdrawal_period = Setting::where('key','order_withdrawal_period')->firstOrFail(); $order_withdrawal_period->value = $plage_days; $order_withdrawal_period->save(); return redirect()->route('bo.creneaux.settings')->with('success', 'Modifications enregistrées !'); } public function saveExceptions(Request $request) { $collecteException = $request->collecte_exception; for ($i = 0; $i < count($collecteException); $i++) { $collecteExceptionToInsert = !empty($collecteException[$i]["date"]); if (isset($collecteException[$i]["id"]) && $collecteException[$i]["id"] !== null && $collecteExceptionToInsert) { $ce = CollecteException::findOrFail($collecteException[$i]["id"]); $ce->date = $collecteException[$i]["date"]; $ce->comment = $collecteException[$i]["comment"]; $ce->save(); } else { if ($collecteExceptionToInsert) { $ce = CollecteException::updateOrCreate(['date' => $collecteException[$i]["date"], 'comment' => $collecteException[$i]["comment"]]); $collecteException[$i]["id"] = $ce->id; } else { unset($collecteException[$i]); $i--; } } } //remet dans l'ordre avant de renvoyer $collecteException = CollecteException::orderBy('date')->get(); return $collecteException; } public function destroyExceptions(Request $request) { $collecteException = CollecteException::findOrFail($request->id); $collecteException->delete(); return "Suppression terminée !"; } }