Last active
August 29, 2015 14:07
-
-
Save n0m4dz/b8d6cc9c3353c43d8375 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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