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

c# - Better 64-bit byte array hash -

webrtc - Which ICE candidate am I using and why? -

php - Zend Framework / Skeleton-Application / Composer install issue -