ingredientRepository = $ingredientRepository; $this->ingredientCategoryRepository = $ingredientCategoryRepository; $this->unitRepository = $unitRepository; $this->supplierRepository = $supplierRepository; } public function index() { $data['title'] = "Ingredient Lists"; $data['ingredients'] = $this->ingredientRepository->findAll(); return view('ingredient::ingredient.index', $data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create Ingredient'; $data['ingredientCategory'] = $this->ingredientCategoryRepository->pluck(); $data['unit'] = $this->unitRepository->pluck(); $data['supplier'] = $this->supplierRepository->pluck(); $data['status'] = Ingredient::STATUS; return view('ingredient::ingredient.create', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request): RedirectResponse { $inputData = $request->all(); $this->ingredientRepository->create($inputData); toastr()->success('Ingredient Created Succesfully'); return redirect()->route('ingredient.index'); } /** * Show the specified resource. */ public function show($id) { $data['title'] = 'Show Ingredient'; $data['ingredient'] = $this->ingredientRepository->getIngredientById($id); $data['status'] = Ingredient::STATUS; return view('ingredient::ingredient.show', $data); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Show Ingredient'; $data['ingredientCategory'] = $this->ingredientCategoryRepository->pluck(); $data['unit'] = $this->unitRepository->pluck(); $data['supplier'] = $this->supplierRepository->pluck(); $data['ingredient'] = $this->ingredientRepository->getIngredientById($id); $data['status'] = Ingredient::STATUS; return view('ingredient::ingredient.edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { $inputData = $request->except(['_method', '_token']); $this->ingredientRepository->update($id, $inputData); return redirect()->route('ingredient.index'); } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $IngredientModel = $this->ingredientRepository->getIngredientById($id); $IngredientModel->delete(); toastr()->success('Ingredient Delete Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return response()->json(['status' => true, 'message' => 'Ingredient Delete Succesfully']); } public function getIngredientDetail(Request $request) { try { $ingredientModel = $this->ingredientRepository->getIngredientById($request->id); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return response()->json([ 'status' => true, 'data' => $ingredientModel, ]); } public function getIngredientsByCategory(Request $request) { $ingredientCategoryId = $request->ingredient_category_id; try { $ingredients = $this->ingredientRepository->getIngredientsByCategory($ingredientCategoryId); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return response()->json(['ingredients' => $ingredients]); } }