productRepository = $productRepository; $this->categoryRepository = $categoryRepository; $this->subCategoryRepository = $subCategoryRepository; $this->fabricCategoryRepository = $fabricCategoryRepository; $this->supplierRepository = $supplierRepository; $this->warehouseRepository = $warehouseRepository; } public function index() { $data['title'] = "Product Lists"; $data['products'] = $this->productRepository->findAll(); return view('product::product.index', $data); } /** * Show the form for creating a new resource. */ public function create() { $data['title'] = 'Create Product'; $data['category'] = $this->categoryRepository->pluck(); $data['fabricCategory'] = $this->fabricCategoryRepository->pluck(); $data['subCategory'] = $this->subCategoryRepository->pluck(); $data['supplier'] = $this->supplierRepository->pluck(); $data['warehouse'] = $this->warehouseRepository->pluck(); $data['status'] = Product::STATUS; return view('product::product.create', $data); } /** * Store a newly created resource in storage. */ public function store(Request $request): RedirectResponse { $inputData = $request->all(); $this->productRepository->create($inputData); toastr()->success('Product Created Succesfully'); return redirect()->route('product.index'); } /** * Show the specified resource. */ public function show($id) { $data['title'] = 'Show Product'; $data['product'] = $this->productRepository->getProductById($id); $data['status'] = Product::STATUS; return view('product::product.show', $data); } /** * Show the form for editing the specified resource. */ public function edit($id) { $data['title'] = 'Show Product'; $data['category'] = $this->categoryRepository->pluck(); $data['subCategory'] = $this->subCategoryRepository->pluck(); $data['fabricCategory'] = $this->fabricCategoryRepository->pluck(); $data['supplier'] = $this->supplierRepository->pluck(); $data['warehouse'] = $this->warehouseRepository->pluck(); $data['product'] = $this->productRepository->getProductById($id); $data['status'] = Product::STATUS; return view('product::product.edit', $data); } /** * Update the specified resource in storage. */ public function update(Request $request, $id): RedirectResponse { $inputData = $request->except(['_method', '_token']); $this->productRepository->update($id, $inputData); return redirect()->route('product.index'); } /** * Remove the specified resource from storage. */ public function destroy($id) { try { $ProductModel = $this->productRepository->getProductById($id); $ProductModel->delete(); toastr()->success('Product Delete Succesfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return response()->json(['status' => true, 'message' => 'Product Delete Succesfully']); } public function getProductDetail(Request $request) { try { $productModel = $this->productRepository->getProductById($request->id); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return response()->json([ 'status' => true, 'data' => $productModel, ]); } }