get('category', 'packaging'); $isShipping = $category === 'shipping'; $query = PackagingItem::query() ->with(['packagingMaterial', 'supplier']) ->orderBy('name'); if ($isShipping) { $query->whereIn('category', ['shipping', 'label', 'shipping_office']); } else { $query->where('category', 'packaging'); } return view('admin.inventory.packaging-items.index', [ 'values' => $query->get(), 'category' => $category, 'pageTitle' => $isShipping ? __('Versandverpackung') : __('Produktverpackung'), ]); } public function create(Request $request) { $category = $request->get('category', 'packaging'); return view('admin.inventory.packaging-items.form', [ 'model' => new PackagingItem(['active' => true, 'category' => $category === 'shipping' ? 'shipping' : 'packaging', 'weight_grams' => 0]), 'packagingMaterials' => PackagingMaterial::query()->orderBy('pos')->orderBy('name')->get(), 'suppliers' => Supplier::query()->orderBy('name')->get(), 'category' => $category, ]); } public function store(StorePackagingItemRequest $request) { $item = $this->packagingItemRepository->create($request->validated()); \Session::flash('alert-save', '1'); $category = in_array($item->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging'; return redirect()->route('admin.inventory.packaging-items.index', ['category' => $category]); } public function edit(PackagingItem $packagingItem) { $category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging'; return view('admin.inventory.packaging-items.form', [ 'model' => $packagingItem, 'packagingMaterials' => PackagingMaterial::query()->orderBy('pos')->orderBy('name')->get(), 'suppliers' => Supplier::query()->orderBy('name')->get(), 'category' => $category, ]); } public function update(UpdatePackagingItemRequest $request, PackagingItem $packagingItem) { $this->packagingItemRepository->update($packagingItem, $request->validated()); \Session::flash('alert-save', '1'); $category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging'; return redirect()->route('admin.inventory.packaging-items.index', ['category' => $category]); } public function destroy(PackagingItem $packagingItem) { $category = in_array($packagingItem->category, ['shipping', 'label', 'shipping_office']) ? 'shipping' : 'packaging'; $packagingItem->delete(); \Session::flash('alert-success', __('Eintrag gelöscht')); return redirect()->route('admin.inventory.packaging-items.index', ['category' => $category]); } }