Skip to content

Instantly share code, notes, and snippets.

@nicekiwi
Last active August 29, 2015 14:22
Show Gist options
  • Save nicekiwi/2cc2852b67d1d9ded1b8 to your computer and use it in GitHub Desktop.
Save nicekiwi/2cc2852b67d1d9ded1b8 to your computer and use it in GitHub Desktop.
Cache Model Example
<?php
$usersWithComments = Cache::remember('users', $minutes, function()
{
return App\users::with('comments')->get();
});
// or
$users = App\users::with('comments')->get();
Cache::put('usersWithComments', $users, $minutes);
$usersWithComments = Cache::get('usersWithComments');
// in modal
class Users extends Model {
//..
public function comments()
{
$q = $this;
return Cache::remember('usersWithComments', 60, function() use ($q)
{
return $q->with('comments')->get();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment