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


PHP Product::queryable方法代碼示例

本文整理匯總了PHP中app\Product::queryable方法的典型用法代碼示例。如果您正苦於以下問題:PHP Product::queryable方法的具體用法?PHP Product::queryable怎麽用?PHP Product::queryable使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在app\Product的用法示例。


在下文中一共展示了Product::queryable方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: index

 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $products = Product::queryable()->mine()->get();
     return view('products.index', compact('products'));
 }
開發者ID:jhruby23,項目名稱:seed,代碼行數:10,代碼來源:ProductsController.php

示例2: related

 /**
  * Select related products.
  * 
  * @param int $count
  * @return Collection
  */
 public function related($count = 3)
 {
     //select products from the same subcategory
     $related = Product::queryable()->notMine()->whereHas('subcategory', function ($q) {
         $q->where('name', $this->subcategory->name);
     })->whereNotIn('id', [$this->id])->orderBy('views', 'desc')->take($count)->get();
     //if not enough, add products from the same category
     if ($related->count() < $count) {
         $used = array_merge([$this->id], $related->lists('id')->toArray());
         $cat = Product::queryable()->notMine()->whereHas('subcategory.category', function ($q) {
             $q->where('name', $this->category->name);
         })->whereNotIn('id', $used)->orderBy('views', 'desc')->take($count - $related->count())->get();
         $related = $related->merge($cat);
     }
     //if still not enough, add any popular products
     if ($related->count() < $count) {
         $used = array_merge([$this->id], $related->lists('id')->toArray());
         $cat = Product::queryable()->notMine()->whereNotIn('id', $used)->orderBy('views', 'desc')->take($count - $related->count())->get();
         $related = $related->merge($cat);
     }
     return $related;
 }
開發者ID:jhruby23,項目名稱:seed,代碼行數:28,代碼來源:Product.php

示例3: comment

 public function comment()
 {
     $input['product'] = Input::get('product');
     $input['text'] = Input::get('text');
     $input['check'] = Input::get('check');
     $product = Product::queryable()->findOrFail($input['product']);
     if (Hash::check($product->slug, $input['check'])) {
         $comment = new Comment();
         $comment->product_id = $input['product'];
         $comment->writer = Auth::user()->id;
         $comment->message = $input['text'];
         $comment->save();
     }
     $comments = $product->comments;
     return view('products.comments', compact('comments'));
 }
開發者ID:jhruby23,項目名稱:seed,代碼行數:16,代碼來源:PagesController.php


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