middleware('copyreader'); } public function index() { $data = [ 'values' => Ingredient::all(), ]; return view('admin.ingredient.index', $data); } public function edit($id) { if ($id === 'new') { $model = new Ingredient; $model->active = true; } else { $model = Ingredient::with('suppliers')->findOrFail($id); } $data = [ 'model' => $model, 'taxRates' => TaxRate::query()->active()->orderBy('pos')->orderBy('name')->get(), 'deliveryTimes' => DeliveryTime::query()->active()->orderBy('pos')->orderBy('label')->get(), 'suppliers' => Supplier::query()->where('active', true)->orderBy('name')->get(), ]; return view('admin.ingredient.edit', $data); } public function store(StoreIngredientRequest $request) { $data = $request->validated(); $data['default_factor'] = $data['default_factor'] ?? 1.10; $supplierIds = $request->input('supplier_ids', []); unset($data['supplier_ids']); if ($request->input('id') === 'new') { $model = Ingredient::create($data); } else { $model = Ingredient::findOrFail($request->input('id')); $model->fill($data)->save(); } $model->suppliers()->sync($supplierIds); \Session()->flash('alert-save', '1'); return redirect(route('admin_product_ingredients')); } public function delete($id) { if (ProductIngredient::where('ingredient_id', $id)->count()) { \Session()->flash('alert-error', 'Eintrag wird als Produkt-Inhaltsstoff verwendet'); return redirect(route('admin_product_ingredients')); } $model = Ingredient::findOrFail($id); $model->delete(); \Session()->flash('alert-success', 'Eintrag gelöscht'); return redirect(route('admin_product_ingredients')); } }