Posts Learn Components Snippets Categories Tags Tools About
/

Laravel Get Total Relationship Count

Laravel get model based on the total number of relationship

Created on Aug 02, 2021

200 views

To get the model based on the total number of relationships, you can use the "has()" method and provide the condition just like the "where()" clause.

The code example below will return "Post" model that has greater than 6 comments.
<?php

# Posts hasMany Comments
$posts = Post::has('comments', '>', 6)->get();

If you like our tutorial, do make sure to support us by being our Patreon or buy us some coffee ☕️

Load comments for Laravel Get Total Relationship Count

)