Support the ongoing development of Laravel.io →
Database Eloquent

Hey, i'm doing a query in which i want to select all models with a column value smaller than their relationship count.

In my account model i have the following relationship:

public function subscribers()
{
     return $this->hasMany(Subscriber::class);
}

And in my account model i have a column named max_subscribers. I want to get all accounts, which column value "max_subscribers" is smaller than the count of the amount of subscribers an account has by the relationship - to see if the account has more subscribers than it is allowed to have.

How do i achieve this?

Thanks

Last updated 2 years ago.
0

Check this out, look for the "Querying Relationship Existence" section.

Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

razum90 razum90 Joined 30 Jul 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.