mohammad-fouladgar / eloquent-builder

This package provides an advanced filter for Laravel model based on incoming requets.
https://medium.com/@mohammadfouladgarphp/laravel-eloquent-filter-all-in-one-d903ededbd19
MIT License
518 stars 42 forks source link

Support for Laravel Compoships #71

Closed nicholaszuccarelli closed 4 years ago

nicholaszuccarelli commented 4 years ago

I'm having some trouble setting up this package.

The models in my app don't directly inherit the Eloquent Builder as they instead use "Compoships" as a middleman (https://github.com/topclaudy/compoships) for more complex relations.

So in my case, I am trying to perform: $builder = EloquentBuilder::setFilterNamespace('Modules\\To\\Filters\\Invoices') ->to($user->company->invoices(), $request->get('filters')) ->get();

where ->company->invoices() returns a eloquent model relationship instance.

Whereas when I try perform the builder instance, I am getting the following error:

Return value of Fouladgar\EloquentBuilder\EloquentBuilder::resolveQuery() must be an instance of Illuminate\Database\Eloquent\Builder, instance of Awobaz\Compoships\Database\Eloquent\Relations\HasMany returned

Is there any way I can get around this? (Can I override a class perhaps to allow for Compoships instances?) If I were to do ->to(Invoice::class, $request->get('filters')), it does work as expected, but it won't work when I pass a relationship into the ->to() method.

Might I add, this is a fantastic package nonetheless :)

nicholaszuccarelli commented 4 years ago

I'll also add (I've been looking around), Compoships has its own version of the Builder class called \Awobaz\Compoships\Database\Query\Builder (which extends the Illuminate Builder)

mohammad-fouladgar commented 4 years ago

@nicholaszuccarelli
Please check this issue #28 and see if your problem is will be resolve.

nicholaszuccarelli commented 4 years ago

Thank you! :) Binding ->getQuery() onto the end of my statement has fixed the problem!