Oct 18, 2015
0
Level 25
cached ajax Pagination with orderby and where
is it possible to manipulate a cached paginated collection with relationships?
for instance:
if(isset($_GET['page'])
{
$page=$_GET['page'];
}
else{
$page = 0;
}
$product = Cache::remember('product'.$page,7200,function() use($brand){
return Product::with('specs','prices','retailers')
->where('brand','=',$brand)
->orderBy('popularity','desc')
->paginate(20);
});
if($page>0 || isset($_GET['order']))
{
// its an ajax request..
if($_GET['order'] == 'price')
{
// order by price on prices with relationship
}
elseif($_GET['order'] == 'screensize')
{
// order by screensize on specs with relationship
} // etc..
Please or to participate in this conversation.