FutureWeb
3 years ago

cached ajax Pagination with orderby and where

Posted 3 years ago by FutureWeb

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 sign in or create an account to participate in this conversation.