DEV Community

techdurjoy
techdurjoy

Posted on

Laravel Eloquent Limit Eager Loading Data Example

Hi All,

In my Laravel 5.0 app I have an Account model which has a hasMany relationship with an Activity model. I’d like to provide my users with a list view of Accounts along with the timestamp of the most recent Activity for each Account.

For obvious performance reasons, I’d like to eager load the appropriate Activity model for each account. I’ve tried to do this with an eager loading constraint as follows:

Laravel Eloquent Limit Eager Loading Data Example

Top comments (0)