@@ -104,7 +104,7 @@ public function shouldBeSearchable()
104104 public static function search ($ query = '' , $ callback = null )
105105 {
106106 return new Builder (
107- new static , $ query , $ callback , config ('scout.soft_delete ' , false )
107+ new static , $ query , $ callback , static :: usesSoftDelete () && config ('scout.soft_delete ' , false )
108108 );
109109 }
110110
@@ -117,11 +117,10 @@ public static function makeAllSearchable()
117117 {
118118 $ self = new static ();
119119
120- $ softDeletes = in_array (SoftDeletes::class, class_uses_recursive (get_called_class ())) &&
121- config ('scout.soft_delete ' , false );
120+ $ softDelete = static ::usesSoftDelete () && config ('scout.soft_delete ' , false );
122121
123122 $ self ->newQuery ()
124- ->when ($ softDeletes , function ($ query ) {
123+ ->when ($ softDelete , function ($ query ) {
125124 $ query ->withTrashed ();
126125 })
127126 ->orderBy ($ self ->getKeyName ())
@@ -169,8 +168,8 @@ public function unsearchable()
169168 */
170169 public function getScoutModelsByIds (Builder $ builder , array $ ids )
171170 {
172- $ query = in_array (SoftDeletes::class, class_uses_recursive ( $ this ) )
173- ? $ this ->withTrashed () : $ this ->newQuery ();
171+ $ query = static :: usesSoftDelete ( )
172+ ? $ this ->withTrashed () : $ this ->newQuery ();
174173
175174 if ($ builder ->queryCallback ) {
176175 call_user_func ($ builder ->queryCallback , $ query );
@@ -321,4 +320,14 @@ public function getScoutKeyName()
321320 {
322321 return $ this ->getQualifiedKeyName ();
323322 }
323+
324+ /**
325+ * Determine if the current class should use soft deletes with searching.
326+ *
327+ * @return bool
328+ */
329+ protected static function usesSoftDelete ()
330+ {
331+ return in_array (SoftDeletes::class, class_uses_recursive (get_called_class ()));
332+ }
324333}
0 commit comments