本文整理汇总了PHP中app\Product::whereRaw方法的典型用法代码示例。如果您正苦于以下问题:PHP Product::whereRaw方法的具体用法?PHP Product::whereRaw怎么用?PHP Product::whereRaw使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Product
的用法示例。
在下文中一共展示了Product::whereRaw方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: showProductByCategory
/**
* @param $id
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
*
* SHOW PRODUCTS BY CATEGORIES
*/
public function showProductByCategory($id)
{
$products = Product::whereRaw("category_id = {$id} and status = true")->orderBy('published_at', 'desc')->with('category', 'tags', 'image')->paginate(10);
if ($id == 1) {
$cat_product = "sabres lasers";
} elseif ($id == 2) {
$cat_product = "casques";
}
return view('front.categories.index', compact('products', 'cat_product'));
}
示例2: getCategory_Product
/**
* Products by Category
* @param [type] $id [description]
* @return [type] [description]
*/
protected function getCategory_Product($id = 0)
{
if ($id == 0) {
return Product::whereRaw('status_product <> 0')->get();
} else {
$category = Category::find($id);
$product = Category::find($id)->product()->whereRaw('status_product <> 0')->get();
return array('name' => $category->name, 'list' => $product);
}
}
示例3: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store(Request $request)
{
$product = $request->get('product');
$quantity = $request->get('quantity');
$data = [];
for ($i = 0; $i < count($product); $i++) {
if (!$product[$i] || !$quantity[$i] || $quantity[$i] <= 0 || !is_integer((int) $quantity[$i])) {
$errors[] = 'product and quantity is required and > 0';
}
$data[] = ['product_id' => $product[$i], 'quantity' => $quantity[$i]];
}
if (isset($errors) && count($errors) > 0) {
return redirect()->back()->withErrors($errors)->with('products', $data);
}
$ids = implode(',', $product);
$products = Product::whereRaw("id IN ({$ids})")->get();
$counter = 0;
foreach ($products as $product) {
if ($product->quantity < $data[$counter]['quantity']) {
$errors[] = $product->name . 'quantity must be reduced' . ' max(' . $product->quantity . ')';
}
$counter++;
}
if (isset($errors) && count($errors) > 0) {
return redirect()->back()->withErrors($errors)->with('products', $data);
}
DB::transaction(function () use($data) {
$newData = [];
foreach ($data as $value) {
$newData[$value['product_id']] = ['quantity' => $value['quantity']];
}
$order = Order::create(['status' => 1, 'user_id' => Auth::user()->id, 'address_id' => null]);
$order->products()->attach($newData);
$order->setQuantity($increase = false);
event(new OrderWasPlaced($this->user, $order));
});
return redirect(route('orders.index'))->with('success', 'Order successful created');
}
示例4: searchNameProduct
/**
* find a products by name
* @return [type] [description]
*/
protected function searchNameProduct($nameproduct)
{
return $a = Product::whereRaw("name like '%{$nameproduct}%' and status_product <> 0")->get()->toArray();
}