I have 2 tables as below:
Subscription
table have a entrance_limit
column, and it has a hasMany('Attendance')
relationship. The entrance_limit
column will actually limit the number of rows in Attendance
. For example, if the entrance_limit
value is 10, then we only can create 10 rows in Attendance
.
Attendance
table has a belongsTo('Subscription')
relationship.
How do I get the list of Subscription
that have total number of Attendance
less than the entrance_limit
value?
Subscription::whereHas('attendances', function($q) {
## something like this
$q->count() < subscription->entrance_limit
})