Skip to content

Instantly share code, notes, and snippets.

@vinicius73
Created February 27, 2014 14:07
Show Gist options
  • Save vinicius73/9250736 to your computer and use it in GitHub Desktop.
Save vinicius73/9250736 to your computer and use it in GitHub Desktop.
Load relations com cache Laravel
<?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