Created
February 27, 2014 14:07
-
-
Save vinicius73/9250736 to your computer and use it in GitHub Desktop.
Load relations com cache Laravel
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 | |
$query = MyModel::orderBy('name', 'ASC'); | |
//Sem cache | |
$query->with('relation1','relation2'); | |
//Com Cache | |
$query->with( | |
[ | |
'relation1' => function ($q){ | |
$q->remember(25); | |
}, | |
'relation2' => function ($q) { | |
$q->remember(25); | |
}, | |
] | |
); | |
//Sem o cache dos relations só a query principal vai para o cache, forcando a repetir as outras querys sempre | |
$result = $query->remember(25)->get(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment