stockRepository = $stockRepository; $this->productRepository = $productRepository; $this->stockLocationRepository = $stockLocationRepository; } public function index() { $data['title'] = 'Stocks List'; $data['stocks'] = $this->stockRepository->findAll(); return view('stock::stock.index', $data); } public function create() { $data['title'] = 'Create Stock'; $data['stockLocation'] = $this->stockLocationRepository->pluck(); $data['product'] = $this->productRepository->pluck(); $data['status'] = Stock::STATUS; return view('stock::stock.create', $data); } public function store(Request $request): RedirectResponse { $request->request->add(['slug' => slugify($request->title)]); $inputData = $request->all(); $this->stockRepository->create($inputData); toastr()->success('Stock Created Successfully'); return redirect()->route('stock.index'); } public function show($id) { $data['title'] = 'Show Stock'; $data['status'] = Stock::STATUS; $data['stock'] = $this->stockRepository->getStockById($id); return view('stock::stock.show', $data); } public function edit($id) { $data['title'] = 'Edit Stock'; $data['stockLocation'] = $this->stockLocationRepository->pluck(); $data['product'] = $this->productRepository->pluck(); $data['status'] = Stock::STATUS; $data['stock'] = $this->stockRepository->getStockById($id); return view('stock::stock.edit', $data); } public function update(Request $request, $id): RedirectResponse { $inputData = $request->except(['_method', '_token']); $this->stockRepository->update($id, $inputData); return redirect()->route('stock.index'); } public function destroy($id) { try { $stock = $this->stockRepository->getStockById($id); $stock->delete(); toastr()->success('Stock Deleted Successfully'); } catch (\Throwable $th) { toastr()->error($th->getMessage()); } return response()->json(['status' => true, 'message' => 'Stock Deleted Successfully']); } }