jarektkaczyk / eloquence

Extensions for the Eloquent ORM
http://softonsofa.com
MIT License
1.09k stars 142 forks source link

Searching many-to-many with pivot table #227

Closed TheClassified closed 6 years ago

TheClassified commented 6 years ago

Hello,

I am currently trying to use the search function from eloquence, for the relevancy search. However I have a many-to-many relation where I need to search on the pivot table.

Is this possible within eloquence? If so, how?

My current code of what I imagined would work.

protected function searchItems($query, $limit = 10) {
        return Item::with('vendors')->with('manufacturer')->with('unit')->with('items')->with('images')->search($query, [
                    'vendors.name' => 10,
                    'vendors.pivot.vendor_part_number' => 3,
                ])
                ->limit($limit)
                ->get();
}

This code provides me with the following exception "Call to undefined method Illuminate\Database\Query\Builder::pivot()"

jarektkaczyk commented 6 years ago

not supported, sorry mate!