Skip to content

Instantly share code, notes, and snippets.

@n0m4dz
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save n0m4dz/b8d6cc9c3353c43d8375 to your computer and use it in GitHub Desktop.
Save n0m4dz/b8d6cc9c3353c43d8375 to your computer and use it in GitHub Desktop.
<?php
private $model;
public function __construct()
{
$this->model = new Post;
}
public function getPosts($myCache) {
if (!Cache::has($myCache)) {
Cache::rememberForever($myCache, function () use ($myCache) {
$posts = array(
'total' => $this->model->count();,
'items' => $this->model->paginate(10)->getItems()
);
return $posts;
});
}
$posts = Cache::get($myCache);
$paginator = Paginator::make($posts['items'], $posts['total'], 10);
return $paginator;
}
?>
<?php
public function getBoxes($cache, array $args = array()) {
if (!Cache::has('boxes_' . $cache)) {
Cache::rememberForever('boxes_' . $cache, function () use ($cache, $args) {
$query = DB::table('box');
$query->select('id', 'title', 'thumb', 'units', 'color', 'price', 'rating');
if (count($args) > 0) {
foreach ($args as $column => $value) {
$query->where($column, $value);
}
}
$boxes = array(
'total' => $query->count(),
'items' => $query->paginate(25)->getItems()
);
return $boxes;
});
}
$boxes = Cache::get('boxes_' . $cache);
$paginator = Paginator::make($boxes['items'], $boxes['total'], 25);
return $paginator;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment