yabhq / laravel-scout-mysql-driver

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

Include softDeletes in search results #42

Open rico opened 7 years ago

rico commented 7 years ago

Is there a way to include soft deleted models in the search results?

I tried several approached found around the net with no luck.

Maybe this is related to #17?

sembrex commented 7 years ago

i modified this engine a little to do the trick added these lines in src/Engines/MySQLEngine.php

// line 59
if ($builder->callback) {
    $query = call_user_func($builder->callback, $query);
}

and then i could do this in my controller

$products = Product::search($request->keyword, function($query) {
    return $query->active()->withTrashed(); // local scope and soft deletes
})->paginate(20);
chrispage1 commented 6 years ago

@sembrex - will this package already respect global scopes as it's querying the relevant table?

Taelkir commented 3 years ago

This is what I've had to use to get soft deletes in my results:

MyModel::search($text, function ($query) {
    return $query->onlyTrashed();
})->get();

Weirdly, only works with the 'soft_delete' boolean set to 'false' in app/scout.php