Skip to content

Commit

Permalink
add makeAllSearchableUsing
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Oct 14, 2020
1 parent d6a08be commit bf8585e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Searchable.php
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,27 @@ 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();
})
->orderBy($self->getKeyName())
->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.
*
Expand Down
8 changes: 8 additions & 0 deletions tests/SearchableTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bf8585e

Please sign in to comment.