当前位置: 首页>>代码示例>>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;未经允许,请勿转载。