jeudi 7 juillet 2016

Is it possible to Cache only the relations in Laravel/Eloquent?

I use the following code to pull data using eloquent

SurveyInterview::surveyAndCall($this->interview->surveyId, $this->interview->callId)
                                  ->with([
                                            'current_step.page',
                                            'pages'
                                        ])
                                  ->first();

How can I cache only the current_step.page and the pages collections since these are the only 2 that do not change?

Based on the feedback in this post http://ift.tt/29q16Bf I tried the following

$myInterview = SurveyInterview::surveyAndCall($this->interview->surveyId, $this->interview->callId)
                                  ->with([
                                            'current_step.page' => function($query){ $query->remember(180); },
                                            'pages'
                                        ])
                                  ->first();

but this gives me an error

Call to undefined method Illuminate\Database\Query\Builder::remember()



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire