File tree Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Expand file tree Collapse file tree 3 files changed +40
-1
lines changed Original file line number Diff line number Diff line change @@ -121,7 +121,7 @@ protected function searchModels(Builder $builder)
121121 return $ models ;
122122 }
123123
124- return $ models ->filter (function ($ model ) use ($ builder ) {
124+ return $ models ->first ()-> makeSearchableUsing ( $ models )-> filter (function ($ model ) use ($ builder ) {
125125 if (! $ model ->shouldBeSearchable ()) {
126126 return false ;
127127 }
Original file line number Diff line number Diff line change 22
33namespace Laravel \Scout \Tests \Feature ;
44
5+ use Illuminate \Database \Eloquent \Model ;
56use Illuminate \Foundation \Testing \LazilyRefreshDatabase ;
7+ use Laravel \Scout \Tests \Fixtures \SearchableModelWithUnloadedValue ;
68use Laravel \Scout \Tests \Fixtures \SearchableUserModel ;
79use Laravel \Scout \Tests \Fixtures \SearchableUserModelWithCustomSearchableData ;
810use Orchestra \Testbench \Concerns \WithLaravelMigrations ;
@@ -139,4 +141,13 @@ public function test_it_can_order_by_latest_and_oldest()
139141 $ this ->assertCount (1 , $ models );
140142 $ this ->assertEquals ('Taylor Otwell ' , $ models [0 ]->name );
141143 }
144+
145+ public function test_it_calls_make_searchable_using_before_searching ()
146+ {
147+ Model::preventAccessingMissingAttributes (true );
148+
149+ $ models = SearchableModelWithUnloadedValue::search ('loaded ' )->get ();
150+
151+ $ this ->assertCount (2 , $ models );
152+ }
142153}
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Laravel \Scout \Tests \Fixtures ;
4+
5+ use Illuminate \Foundation \Auth \User as Model ;
6+ use Illuminate \Support \Collection ;
7+ use Laravel \Scout \Searchable ;
8+
9+ class SearchableModelWithUnloadedValue extends Model
10+ {
11+ use Searchable;
12+
13+ protected $ table = 'users ' ;
14+
15+ public function toSearchableArray ()
16+ {
17+ return [
18+ 'value ' => $ this ->unloadedValue ,
19+ ];
20+ }
21+
22+ public function makeSearchableUsing (Collection $ models )
23+ {
24+ return $ models ->each (
25+ fn ($ model ) => $ model ->unloadedValue = 'loaded ' ,
26+ );
27+ }
28+ }
You can’t perform that action at this time.
0 commit comments