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
Post a Comment