get(); return view('bo.reductions.index', compact('r', 'ranges')); } public function saveDatas(UpdateReductionRequest $request) { $reductionId = $request->reductionId; $products = $request->products; $ranges = $request->ranges; $notification = $request->notification === null ? 0 : 1; $reduction = Reduction::find($reductionId); $reduction->ranges()->sync($ranges); foreach ($ranges as $rangeId) { $range = $reduction->ranges()->where('range_id', $rangeId)->first(); foreach ($products as $product) { if (in_array($product, $range->products()->pluck('id')->toArray())) { array_splice($products, array_search($product, $products), 1); } } } $reduction->products()->sync($products); $reduction->notification = $notification; $reduction->save(); if ($notification === 1) { event(new NewNotification(NotificationType::reduction(), route('club.reductions'), $reduction)); } return "Traitement terminé"; } /** * Permet la mise à jour des bons de réductions depuis MesBR manuellement dans le BO */ public function updateBr() { Reduction::updateBr(); return redirect()->route('bo.reductions.index'); } }