I have two tables, say \"users\" and \"users_actions\", where \"users_actions\" has an hasMany relation with users:
users
id | name
I created a package for this: https://github.com/staudenmeir/eloquent-eager-limit
Use the HasEagerLimit trait in both the parent and the related model.
class User extends Model {
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
class Action extends Model {
use \Staudenmeir\EloquentEagerLimit\HasEagerLimit;
}
Then you can apply ->limit(1) to your relationship and you will get the latest action per user.