public function save(Request $request, $id = NULL)
 {
     if (isset($id)) {
         Product::updateOrCreate(["id" => $id], $request->input());
     } else {
         Product::create($request->input());
     }
     return redirect("/products");
 }
Example #2
0
 private function storeProduct($data)
 {
     $data = $this->mapProductData($data);
     $product = Product::updateOrCreate(['sku' => $data['sku']], $data);
     // add link to channel via pivot table
     // inefficient should refactor
     if (!$product->channels->contains($this->channel->id)) {
         $product->channels()->attach($this->channel->id);
     }
     return $product;
 }
Example #3
0
 /**
  * Show the application dashboard to the user.
  *
  * @return Response
  */
 public function create(Request $request)
 {
     //		dd($request->input());
     $data = array('errNum' => 0, 'errMsg' => '', 'errDate' => '');
     $title = empty($request->input("title")) ? 0 : $request->input("title");
     $type = empty($request->input("special")) ? 0 : $request->input("special");
     $content = empty($request->input("content")) ? 0 : $request->input("content");
     $image = empty($request->input("image")) ? 0 : $request->input("image");
     $images = empty($request->input("imagepath")) ? 0 : $request->input("imagepath");
     $price = empty($request->input("price")) ? 0 : $request->input("price");
     $deadline = empty($request->input("deadline")) ? 0 : $request->input("deadline");
     $payway = $request->input("payway");
     $product = array();
     $product["pid"] = time() . rand(10000, 99999);
     $product["uid"] = $this->user->id;
     $product["name"] = $title;
     $product["type"] = $type;
     $product["description"] = $content;
     $product["image"] = $image;
     $product["images"] = $images;
     $product["price"] = $price;
     $product["deadline"] = $deadline;
     $product["payway"] = $payway;
     //		dd($product);
     //		if($title!=0 && $type!=0 && $content!=0 && $images!=0 && $price!=0 && $deadline!=0)
     Product::updateOrCreate($product);
     if (view()->exists('product.edit')) {
         return view('product.edit');
     }
     return view('home');
 }