-1

I have customers that have many parcels through orders.

public function parcels()
    {
        return $this->hasManyThrough(Parcel::class, Order::class);
    }

I want to return customers that have parcels more than 0 with successful status only. But I don't know how to add conditions of parcel status. Currently, this statement gives me a list of customers that have parcels. $customers = Customer::has('parcels', '>' , 0)->get();

Junior Frogie
  • 313
  • 1
  • 3
  • 16

1 Answers1

5

You can use the whereHas method.

$customers = Customer::whereHas('parcels', function ($query) {
    $query->where('status', 'successful');
})->get();
Luigel
  • 331
  • 1
  • 7