Lazy Loading a Laravel Model relationship through a repository

If your Laravel Model needs access to repository for pulling relationship data, think again.

It’s the wrong way round, don’t do it. Your models need access to data without any N+1 issues from using Lazy load. So if you need to merge some data streams and return a collection, rather than use a repo call to access each stream object; Create a view table which `Union ALL`’s the data various models. Then the model can have lazy load access to all the things you need, and the laravel commands, `->with()` or `->load()` can work without slowing it all down

Author: Dan Course

Dan Course, E-Learning Development at Warwick University (WMG). Agile Scrum trained and full-stack development. Interested in E-learning, Democracy, Politics and Tech. All thoughts are mine and not of my employer.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s