本文整理汇总了PHP中app\Product::updateOrCreate方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::updateOrCreate方法的具体用法?PHP Product::updateOrCreate怎么用?PHP Product::updateOrCreate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::updateOrCreate方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: save
public function save(Request $request, $id = NULL)
{
if (isset($id)) {
Product::updateOrCreate(["id" => $id], $request->input());
} else {
Product::create($request->input());
}
return redirect("/products");
}
示例2: storeProduct
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;
}
示例3: create
/**
* 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');
}