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)
121
121
return $ models ;
122
122
}
123
123
124
- return $ models ->filter (function ($ model ) use ($ builder ) {
124
+ return $ models ->first ()-> makeSearchableUsing ( $ models )-> filter (function ($ model ) use ($ builder ) {
125
125
if (! $ model ->shouldBeSearchable ()) {
126
126
return false ;
127
127
}
Original file line number Diff line number Diff line change 2
2
3
3
namespace Laravel \Scout \Tests \Feature ;
4
4
5
+ use Illuminate \Database \Eloquent \Model ;
5
6
use Illuminate \Foundation \Testing \LazilyRefreshDatabase ;
7
+ use Laravel \Scout \Tests \Fixtures \SearchableModelWithUnloadedValue ;
6
8
use Laravel \Scout \Tests \Fixtures \SearchableUserModel ;
7
9
use Laravel \Scout \Tests \Fixtures \SearchableUserModelWithCustomSearchableData ;
8
10
use Orchestra \Testbench \Concerns \WithLaravelMigrations ;
@@ -139,4 +141,13 @@ public function test_it_can_order_by_latest_and_oldest()
139
141
$ this ->assertCount (1 , $ models );
140
142
$ this ->assertEquals ('Taylor Otwell ' , $ models [0 ]->name );
141
143
}
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
+ }
142
153
}
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