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

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

c# - Better 64-bit byte array hash -

python - PyCharm Type error Message -