當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Product::whereRaw方法代碼示例

本文整理匯總了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'));
 }
開發者ID:PierreMartin,項目名稱:starwars,代碼行數:16,代碼來源:FrontController.php

示例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);
     }
 }
開發者ID:hoangvu2015,項目名稱:laravel_totnghiep,代碼行數:15,代碼來源:Category.php

示例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');
 }
開發者ID:Tisho84,項目名稱:laravel-work,代碼行數:43,代碼來源:OrdersController.php

示例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();
 }
開發者ID:hoangvu2015,項目名稱:laravel_totnghiep,代碼行數:8,代碼來源:Product.php


注:本文中的app\Product::whereRaw方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。