public function store(EditProductRequest $request)
 {
     $product = new Product();
     $product->fill($request->only($product->getFillable()));
     $product->save();
     return redirect()->route('product.index')->with('success_message', 'The product has been successfully saved.');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateProductRequest $request, Product $product)
 {
     $data = $request->input();
     $product->fill($data);
     $product->save();
     $this->savePhoto($product, $request);
     $product->categories()->detach($product->categories()->lists('id')->toArray());
     $product->categories()->attach($data['categories']);
     return Redirect()->route('home');
 }
 /**
  * Untuk menyimpan data product
  * 
  * @param  Request $request [description]
  * @return [type]           [description]
  */
 public function store(Request $request, Supplierable $supplier)
 {
     $this->validate($request, ['code' => 'required', 'name' => 'required', 'description' => 'required', 'price' => 'required', 'category_id' => 'required']);
     $data = $request->only('code', 'name', 'description', 'price', 'category_id');
     if (is_string($request->get('tags'))) {
         $tags = explode(',', $request->get('tags'));
     } else {
         $tags = $request->get('tags', []);
     }
     $product = new Product();
     $product->fill($data);
     $product->supplier()->associate($supplier);
     $product->save();
     $this->productRepository->saveTags($product, $tags);
     if ($product) {
         return ['status' => 'success', 'message' => 'Product has successfully added.', 'product' => $product];
     } else {
         return ['status' => 'failed', 'message' => 'Product has failed to be added.'];
     }
 }
 /**
  * Store a newly created resource in storage.
  * @return Response
  */
 public function store()
 {
     $validator = Validator::make(Input::all(), Product::$product_rules);
     if ($validator->passes()) {
         $user = Auth::user();
         $file_rename = $this->renameImage();
         if (Request::file('image')->move(public_path() . '/uploads', $file_rename)) {
             $product_data = new Product();
             $product_data->fill(Input::all());
             $product_data['image'] = $file_rename;
             if ($user->product()->save($product_data)) {
                 Session::flash('message.success', 'Item added successfully.');
                 return Redirect::to("home");
             } else {
                 Session::flash('message.arrayErrors', $validator->messages()->all());
                 return Redirect::to('add-product')->withInput(Input::all());
             }
         }
     } else {
         Session::flash('message.arrayErrors', $validator->messages()->all());
         return Redirect::to('add-product')->withInput(Input::all());
     }
 }
 /**
  * Update the specified product
  *
  * @param  ProductRequest $request
  * @param  Product        $product
  * @return Response
  */
 public function update(EditProductRequest $request, Product $product)
 {
     $input = $request->except('image');
     $image = $request->file('image');
     if (!isset($input['active'])) {
         $input['active'] = false;
     }
     if (!isset($input['new'])) {
         $input['new'] = false;
     }
     if ($image != null) {
         // Picture name will be same as SKU
         $name = $input['sku'];
         // Extenstion of original picture
         $extension = '.' . $image->getClientOriginalExtension();
         // Set paths for full image and thumbnail
         $imagePath = 'img/' . $name . $extension;
         $thumbnailPath = 'img/thumbs/' . $name . $extension;
         // Save original picture
         \Image::make($image->getRealPath())->save(public_path($imagePath));
         // Save resized thumbnail
         \Image::make($image->getRealPath())->resize(300, null, function ($constraint) {
             $constraint->aspectRatio();
         })->save(public_path($thumbnailPath));
         // Create Product model and save pictures
         $product->fill($input);
         $product->image = $imagePath;
         $product->image_thumb = $thumbnailPath;
         $product->save();
         return redirect(route('AdminProductShow', $product->slug));
     }
     $product->fill($input);
     $product->save();
     return redirect(route('AdminProductShow', $product->slug));
 }