Exemplo n.º 1
0
 /**
  *  edit product
  *
  * @param $domain
  * @param $id
  * @param Request $request
  * @return \BladeView|bool|\Illuminate\Http\RedirectResponse|\Illuminate\View\View
  */
 public function editProduct($domain, $id, Request $request)
 {
     $productService = new productService();
     $addressService = new addressService();
     $productGalleryModel = new productGalleryModel();
     $tagService = new tagService();
     $results = [];
     try {
         if ($request->isMethod('post')) {
             $productService->updateProduct($request->all(), $id);
             return redirect('/product/editProduct/' . $id)->with('success', 'Cập nhật sản phẩm thành công!');
         }
         $results['product'] = $productService->getProductById($id, 0, false);
         $results['tagColor'] = $tagService->getColorTag();
         $results['groupTag'] = $tagService->getTagGroup();
         $results['tagSize'] = $tagService->getSizeTag();
         $results['tagStyle'] = $tagService->getStyleTag();
         $results['countries'] = $addressService->getListCountry();
         $results['images'] = $productGalleryModel->getImagesProductByProductId($id);
         return view('admin.product.edit-product', $results);
     } catch (\Exception $e) {
         if ($request->ajax()) {
             $result['error'] = $e->getMessage();
             return $result;
         } else {
             return view('errors.404', ['error_message' => $e->getMessage()]);
         }
     }
 }