コード例 #1
0
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  * @param Category $category
  * @param Product $product
  * @return User
  */
 public function create(array $data, Category $category, Product $product)
 {
     $pictureName = $this->extractPicture($data['picture'], $category, $product);
     $picture = Picture::create(['filename' => $pictureName]);
     $picture->product()->associate($product)->save();
     return $picture;
 }
コード例 #2
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;
 }
コード例 #3
0
 /**
  * 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]);
 }