I am trying to select from a table, but I only want to select things that have an existing relationship.
So, like, if I have Users and Comments. Users haveMany Comments.
I want to do something like:
User::hasComments()->paginate(20);
So, I only want to paginate users that have at least 1 comment. Is there any way to do this?
Thanks!
You're close! ;)
User::has('comments')->paginate();
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community