Skip to content

Commit bf8585e

Browse files
committed
add makeAllSearchableUsing
1 parent d6a08be commit bf8585e

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Searchable.php

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,13 +123,27 @@ public static function makeAllSearchable($chunk = null)
123123
$softDelete = static::usesSoftDelete() && config('scout.soft_delete', false);
124124

125125
$self->newQuery()
126+
->when(true, function ($query) use ($self) {
127+
$self->makeAllSearchableUsing($query);
128+
})
126129
->when($softDelete, function ($query) {
127130
$query->withTrashed();
128131
})
129132
->orderBy($self->getKeyName())
130133
->searchable($chunk);
131134
}
132135

136+
/**
137+
* Modify the query used to retrieve models when making all of the models searchable.
138+
*
139+
* @param \Illuminate\Database\Eloquent\Builder $query
140+
* @return \Illuminate\Database\Eloquent\Builder
141+
*/
142+
protected function makeAllSearchableUsing($query)
143+
{
144+
return $query;
145+
}
146+
133147
/**
134148
* Make the given model instance searchable.
135149
*

tests/SearchableTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,14 @@ public function newQuery()
6666
{
6767
$mock = m::mock(Builder::class);
6868

69+
$mock->shouldReceive('when')
70+
->with(true, m::type('Closure'))
71+
->andReturnUsing(function ($condition, $callback) use ($mock) {
72+
$callback($mock);
73+
74+
return $mock;
75+
});
76+
6977
$mock->shouldReceive('orderBy')
7078
->with('id')
7179
->andReturnSelf()

0 commit comments

Comments
 (0)