routeModel(); $reassignTo = (int) request()->input('reassign_to', 0); $guard = app(DeletionGuard::class); $blockers = $guard->blockersFor($location); if ($blockers !== []) { $target = $reassignTo > 0 && $reassignTo !== $location->id ? Location::query()->find($reassignTo) : null; if (! $target) { \Session::flash('alert-error', __('Lagerort ist noch belegt — bitte einen Ziel-Lagerort zum Übernehmen der Buchungen wählen.')); return redirect()->route($this->redirectRoute()); } DB::transaction(function () use ($location, $target) { StockEntry::query()->where('location_id', $location->id)->update(['location_id' => $target->id]); Production::query()->where('location_id', $location->id)->update(['location_id' => $target->id]); StockDisposal::query()->where('location_id', $location->id)->update(['location_id' => $target->id]); $location->delete(); }); \Session::flash('alert-success', __('Lagerort gelöscht — Buchungen auf „:target" übernommen.', ['target' => $target->name])); return redirect()->route($this->redirectRoute()); } $location->delete(); \Session::flash('alert-success', __('Eintrag gelöscht')); return redirect()->route($this->redirectRoute()); } protected function modelClass(): string { return Location::class; } protected function viewPrefix(): string { return 'admin.inventory.locations'; } protected function redirectRoute(): string { return 'admin.inventory.locations.index'; } protected function storeRequestClass(): string { return StoreLocationRequest::class; } protected function newModelAttributes(): array { return ['active' => true]; } protected function indexOrder(): array { return ['name']; } }