Guest User

Untitled

a guest
Feb 17th, 2018
112
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. /**
  2. * Cache delete handler for Laravel 5.1 pagination.
  3. *
  4. * @array list of laravel cache keys
  5. * @param int $totalResults Total results for pagination
  6. * @param int $perPage Page results
  7. * @return Response
  8. *
  9. * You need to cache your pages with this key pattern:
  10. * Cache::rememberForever('key.' . $currentPage , function(){});
  11. * Default $currentPage must be 1
  12. * if(!$currentPage)$currentPage = 1
  13. */
  14.  
  15. public function clearPaginateCache(array $array, $totalResults, $perPage)
  16. {
  17. $totalPages = ceil($totalResults/$perPage) + 1;
  18.  
  19. foreach ($array as $key => $value)
  20. {
  21. for($x = 1; $x <= $totalPages; $x++)
  22. {
  23. Cache::forget($value . "." . $x);
  24. }
  25. }
  26. }
Add Comment
Please, Sign In to add comment