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

Popular posts from this blog

python - pip install -U PySide error -

arrays - C++ error: a brace-enclosed initializer is not allowed here before ‘{’ token -

cytoscape.js - How to add nodes to Dagre layout with Cytoscape -