Hi Ive Followed Jeff Lesson, but i did more than he did such as filtering many to many relationship
Product BelongsToMany Category
and
Category BelongsToMany Product
$products = Product::filter($filters)->published()->distinct()->get(['id', 'name', 'description', 'caption', 'price', 'image', 'slug', 'sku', 'thumbnail', 'options', 'rating_cache', 'rating_count', 'views']);
The Following are the Method in My ProductFilters
public function popular($order = 'desc')
{
return $this->builder->orderBy('views', $order);
}
/**
* Filter by Category.
*
* @param string $level
* @return Builder
*/
public function categories($categories = [])
{
if(!is_array($categories)){
return $this;
}
return $this->builder
->join('category_product', 'category_product.product_id', '=', 'products.id')
->whereIn('category_product.category_id', $categories);
}
/**
* Filter by No of Star Review.
*
* @param string $order
* @return Builder
*/
public function starrating($order)
{
return $this->builder->where('rating_cache', '>=', $order);
}
/**
* Filter by Product With Most No of Reviews
*
* @param string $order
* @return Builder
*/
public function reviewcount($order = 'desc')
{
return $this->builder->orderBy('rating_count', $order);
}
/**
* Filter by No of Results You Want to Get
*
* @param string $order
* @return Builder
*/
public function take($count = null)
{
if(empty($count)){
return $this;
}
if(is_numeric($count)){
return $this->builder->limit($count);
}
return $this;
}
Now With These Code i can Filter Exactly What i Want...
But the Only Problem i Got Now is How Can i Paginate the Result
Coz if i add ->paginate(10) before ->get() method , the code is totally messed up and im receiving error
how ever if i remove the get() method and add the paginate(10) method.
My Result Shows Multiple , It shows the same product multiple times.
On Top Of That the Querry String Produce
{!! (new App\Pagination($products))->render() !!}
By Lavish Pagination package doesnt have all the querry string below which should be appended.
On the pagination.
http://mysite.dev/products?categories%5B%5D=1&categories%5B%5D=3&popular=desc&starrating=0&reviewcount=desc&take=all
ive Seen Laracast Uses Has Such Filter as Mine but Dont Duplicate Result...
Calling @Jeffrey_Way