Last active
August 29, 2015 14:22
-
-
Save nicekiwi/2cc2852b67d1d9ded1b8 to your computer and use it in GitHub Desktop.
Cache Model Example
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 | |
$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