Пример #1
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index()
 {
     $products = Product::queryable()->mine()->get();
     return view('products.index', compact('products'));
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 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'));
 }