Laravel 4 - auto eager load
I just found out that there is a way to eager load some relationships with Laravel 4 for every fetch you make. Following is from Model.php
/**
* The relations to eager load on every query.
*
* @var array
*/
protected $with = array();
You just need to set $with
array in your model.
protected $with = array('foo', 'bar');
just add this to your model, and everything in that array, will be eager loaded.
Written by Umut Sirin
Related protips
1 Response
Awesome tip thanks!
over 1 year ago
·
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Php
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#