buildwithyab/laravel-scout-mysql-driver

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

Opened this issue · 2 comments

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?

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.

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