Ejemplo n.º 1
0
 /**
  * update a product
  *
  * @param  array $data
  * @param Category $category
  * @param Product $product
  * @param Picture $pictureModel
  * @return Product
  */
 public function update(array $data, Category $category, Product $product, Picture $pictureModel)
 {
     $updateArray = [];
     foreach ($data as $key => $value) {
         if ($value !== '') {
             switch ($key) {
                 case 'new_product_id':
                     //find the new product by its id
                     $newProduct = Product::findOrFail($data['new_product_id']);
                     //associate with the new product
                     $pictureModel->product()->associate($newProduct)->save();
                     break;
                 case 'picture':
                     $updateArray['filename'] = $this->extractPicture($value, $category, $product, $pictureModel);
                     break;
             }
         }
     }
     $pictureModel->update($updateArray);
     return $pictureModel;
 }
 /**
  * If it succeded
  *
  * @return \Illuminate\View\View
  */
 public function success()
 {
     $product = Product::findOrFail($this->request->input('productId'));
     //get the user
     $user = $this->auth->user();
     return view('orders.success', compact('product', 'user'));
 }
 /**
  * Update the specified resource in storage.
  *
  * @param $categoryId
  * @param $productId
  * @return Response
  */
 public function update($categoryId, $productId)
 {
     $this->updaterar->validator($this->request);
     $category = Category::findOrFail($categoryId);
     $product = Product::findOrFail($productId);
     $this->updaterar->update($this->request->all(), $category, $product);
     return redirect()->route('category.products.index', $category->id);
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param $categoryId
  * @param $productId
  * @param  int $id
  * @return Response
  */
 public function destroy($categoryId, $productId, $id)
 {
     $category = Category::findOrFail($categoryId);
     $product = Product::findOrFail($productId);
     $picture = Picture::findOrFail($id);
     $picture->delete();
     return redirect()->route('category.products.pictures.index', [$category->id, $product->id]);
 }