From bf8585eaff9204d23602f9c064b7e3cc074212e2 Mon Sep 17 00:00:00 2001 From: Taylor Otwell Date: Wed, 14 Oct 2020 14:01:05 -0500 Subject: [PATCH] add makeAllSearchableUsing --- src/Searchable.php | 14 ++++++++++++++ tests/SearchableTest.php | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Searchable.php b/src/Searchable.php index ee06bc50..13fc1138 100644 --- a/src/Searchable.php +++ b/src/Searchable.php @@ -123,6 +123,9 @@ public static function makeAllSearchable($chunk = null) $softDelete = static::usesSoftDelete() && config('scout.soft_delete', false); $self->newQuery() + ->when(true, function ($query) use ($self) { + $self->makeAllSearchableUsing($query); + }) ->when($softDelete, function ($query) { $query->withTrashed(); }) @@ -130,6 +133,17 @@ public static function makeAllSearchable($chunk = null) ->searchable($chunk); } + /** + * Modify the query used to retrieve models when making all of the models searchable. + * + * @param \Illuminate\Database\Eloquent\Builder $query + * @return \Illuminate\Database\Eloquent\Builder + */ + protected function makeAllSearchableUsing($query) + { + return $query; + } + /** * Make the given model instance searchable. * diff --git a/tests/SearchableTest.php b/tests/SearchableTest.php index d3267c3e..a8a0abaa 100644 --- a/tests/SearchableTest.php +++ b/tests/SearchableTest.php @@ -66,6 +66,14 @@ public function newQuery() { $mock = m::mock(Builder::class); + $mock->shouldReceive('when') + ->with(true, m::type('Closure')) + ->andReturnUsing(function ($condition, $callback) use ($mock) { + $callback($mock); + + return $mock; + }); + $mock->shouldReceive('orderBy') ->with('id') ->andReturnSelf()