php - Laravel Eloquent, select only rows where the relation exists -
i trying select table, want select things have existing relationship.
for example, if have users , comments, , users havemany comments, want like:
user::hascomments()->paginate(20);
so, want select users have @ least 1 comment, , paginate result of query. there way this?
according laravel's eloquent documentation "querying relations when selecting", should work:
user::has('comments')->paginate(20);
Comments
Post a Comment