Laravel Where Count > N

前端 未结 3 1411
攒了一身酷
攒了一身酷 2021-01-24 07:22

I have 2 models in my app:

1. Customer.php

2. Car.php

Now I would like to run a query that returns all customers that h

3条回答
  •  一向
    一向 (楼主)
    2021-01-24 07:48

    Use this:

    $customers = Customer::withCount('cars')
        ->having('cars_count', '<', 2)
        ->get();
    

提交回复
热议问题