laravel - Automatic eager loading? -


rather doing (which dozens of times across site):

$posts = post::with('user')     ->with('image')     ->get(); 

is possible automatically call with('image') whenever with('user') called? in end, just:

$posts = post::with('user')     ->get(); 

and still eager load image?

add following in model:

protected $with = array('image'); 

and should trick.

the $with attribute lists relations should eagerly loaded every query.


Comments

Popular posts from this blog

android - questions about switching from C2DM to GCM -

c++ - Qt setGeometry: Unable to set geometry -

batch file - How to extract all multi-volume RAR archives from subfolders of a folder? -