yabhq / laravel-scout-mysql-driver

Laravel Scout MySQL Driver
MIT License
522 stars 113 forks source link

Search doesn't work with `with` or `load` #108

Open vanvanni opened 4 years ago

vanvanni commented 4 years ago

I want to load in my relation when using search but I cannot use the with() method. I have been searching around for solutions and people starting to use load() but that is also not available.

What options do I have left here?

sbreiler commented 4 years ago

Hi, i just came across the same problem, i got it down to:

        $search = [
            'term' => $request->input('term', '')
        ];

        if( $search['term'] ) {
            $list = MyModel::search($search['term'])->query(function($builder) {
                /** @var \Illuminate\Database\Eloquent\Builder $builder */
                $builder
                    ->with('latestAudit');
            });
        }
        else {
            $list = MyModel::with('latestAudit');
        }

        $list = $list->paginate(20);

Not pretty, but it works for me.

sbreiler commented 4 years ago

Ah... i just saw it wont work, see #102