public function postShoppingProduct(Request $request, ShoppingInformationInterface $infoRepo, UserInterface $userRepo, ProductInterface $productRepo) { $data = $request->all(); if ($request->get('price') > Auth::user()->balance) { return redirect()->back()->with('error_danger', 'Դուք չունեք բավարար գումար գնում կատարելու համար'); } $productsId = explode(',', $data['idsProduct']); unset($productsId[0]); $infosId = explode(',', $data['idsInfo']); unset($infosId[0]); foreach ($productsId as $productId) { $product = $productRepo->getOne($productId); $count = $product->count - 1; $result = $productRepo->update(['count' => $count], $productId); } foreach ($infosId as $infoId) { $result = $infoRepo->update(['shopping' => 'Yes'], $infoId); } $balance = Auth::user()->balance - $data['price']; $result = $userRepo->updateOne(Auth::user()->id, ['balance' => $balance]); return redirect()->back()->with('error', 'Ձեր գործարքը հաջողությամբ կատարվեց'); }
/** * Delete a product. * GET /admin/remove-product/{id} * * @param integer $id * @param ProductInterface $productRepo * @return response */ public function getRemoveProduct($id, ProductInterface $productRepo) { $result = $productRepo->remove($id); return redirect()->back(); }