Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Haris1566's avatar

how to get only those records which have more than one records through hasmany relation in laravel

Hi, I have tables called "QuestionType" and "Questions". and I made a relationship in the "QuestionType" model such as:

Every "QuestionType" hasMany "Questions"

so my question is how to get only those "QuestionTypes" that have more than 1 question.

0 likes
1 reply
tykus's avatar
QuestionType::has('questions', '>=', 1)->get()

But >= and 1 are the defaults, so...

QuestionType::has('questions')->get()

Please or to participate in this conversation.