public function store(ProductCreateRequest $request)
 {
     $product = new Product(array('name' => $request->get('name'), 'sku' => $request->get('sku'), 'price' => $request->get('price'), 'description' => $request->get('description'), 'is_downloadable' => $request->get('is_downloadable'), 'authorId' => Auth::user()->id));
     $product->save();
     // Process the uploaded image
     $imageName = $product->sku . '.' . $request->file('image')->getClientOriginalExtension();
     $request->file('image')->move(base_path() . '/public/imgs/products/', $imageName);
     return \Redirect::route('products.index')->with('message', 'The product has been added!');
 }
 public function store(ProductCreateRequest $request)
 {
     $data = $request->all();
     if ($request->file('file') != null) {
         $data = $this->makePic($request->file('file'), $data);
     }
     Product::create($data);
     flash()->success(trans('product.label.name'), trans('product.message_alert.create_success'));
     return redirect('/products');
 }
Beispiel #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(ProductCreateRequest $request)
 {
     $product = new Product(array('name' => $request->get('name'), 'sku' => $request->get('sku'), 'price' => $request->get('price'), 'description' => $request->get('description'), 'is_downloadable' => $request->get('is_downloadable')));
     $product->save();
     // Process the uploaded image
     $imageName = $product->sku . '.' . $request->file('image')->getClientOriginalExtension();
     $request->file('image')->move(base_path() . '/public/imgs/products/', $imageName);
     // Process the electronic download
     if ($request->file('download')) {
         $downloadName = $product->sku . '.' . $request->file('download')->getClientOriginalExtension();
         $request->file('download')->move(storage_path() . '/downloads/', $downloadName);
         $product->download = $downloadName;
         $product->save();
     }
     return \Redirect::route('admin.products.edit', array($product->id))->with('message', 'The product has been added!');
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(ProductCreateRequest $request)
 {
     $name = $request->Input('name');
     $category_id = $request->Input('category_id');
     $brand_id = $request->Input('brand_id');
     $origin_id = $request->Input('origin_id');
     $qty_inventory = $request->Input('qty_inventory');
     $price = $request->Input('price');
     $content = $request->Input('content');
     $discount = $request->Input('discount');
     //Check fileImage
     if ($request->hasFile('image')) {
         $image = $request->file('image');
         $imagename = time() . '-' . $image->getClientOriginalName();
         $image->move(public_path() . '/image', $imagename);
     } else {
         $imagename = null;
     }
     //Status
     if ($request->Input('status_product') == false) {
         $status_product = 0;
     } else {
         $status_product = 1;
     }
     $data = ['name' => $name, 'category_id' => $category_id, 'brand_id' => $brand_id, 'origin_id' => $origin_id, 'qty_inventory' => $qty_inventory, 'price' => $price, 'content' => $content, 'discount' => $discount, 'image' => $imagename, 'status_product' => $status_product];
     //dd($data);
     Product::create($data);
     //dd($data);
     //$category = Category::find($category_id);//dong loai SP.
     // $category->product()->create($data); //store database.
     return redirect()->route('product.index');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update(ProductCreateRequest $request, $id)
 {
     $product = Product::findOrFail($id);
     $product->update(['name' => $request->get('name'), 'sku' => $request->get('sku'), 'price' => $request->get('price'), 'description' => $request->get('description'), 'is_downloadable' => $request->get('is_downloadable')]);
     $imageName = $product->sku . '.' . $request->file('image')->getClientOriginalExtension();
     $request->file('image')->move(base_path() . '/public/imgs/products/', $imageName);
     return \Redirect::route('admin.products.edit', array($product->id))->with('message', 'The product has been updated!');
 }