createInstallation($productionOrder, $request->validated(), $request->user()); $notificationService->notifyProductionOrderEvent( $productionOrder, ProductionOrderNotificationEvent::InstallationAdded, $request->user(), installation: $installation->load('brigadier'), ); return $this->redirectToOrder($request, $productionOrder) ->with('success', 'Монтаж добавлен.'); } public function update( SaveProductionOrderInstallationRequest $request, ProductionOrder $productionOrder, ProductionOrderInstallation $installation, ProductionOrderPlanningService $service, ): RedirectResponse { $this->assertBelongsToOrder($productionOrder, $installation); $service->updateInstallation($installation, $request->validated(), $request->user()); return $this->redirectToOrder($request, $productionOrder) ->with('success', 'Монтаж обновлён.'); } public function destroy( Request $request, ProductionOrder $productionOrder, ProductionOrderInstallation $installation, ProductionOrderPlanningService $service, ): RedirectResponse { $this->assertBelongsToOrder($productionOrder, $installation); $service->deleteInstallation($installation); return $this->redirectToOrder($request, $productionOrder) ->with('success', 'Монтаж удалён.'); } private function assertBelongsToOrder( ProductionOrder $order, ProductionOrderInstallation $installation, ): void { abort_unless($installation->production_order_id === $order->id, 404); } private function redirectToOrder(Request $request, ProductionOrder $order): RedirectResponse { return redirect()->route('schedule.orders.show', $this->withNav( ['productionOrder' => $order], $this->resolveNavToken($request), )); } }