nicolaslopezj / searchable

A php trait to search laravel models
MIT License
2.01k stars 291 forks source link

no results when calling search() after a whereHas #213

Open cyberhicham opened 4 years ago

cyberhicham commented 4 years ago

I have a scope which is created using whereHas :

public function scopeVendorOf($query, Enterprise $customer)
    {
        return $query->whereHas('customers', function ($query) use ($customer) {
            $query->where('id', $customer->id);
        });
    }

now if I call this scope before the search scope it works, but calling the search scope before the vendorOf() one will fail.

Enterprise::search('lucas',null,true,true)->vendorOf($customer)->count() => 0 Enterprise::vendorOf($customer)->search('lucas',null,true,true)->count() => 1

Any idea why and how to solve this issue ?