File tree Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Expand file tree Collapse file tree 2 files changed +12
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,12 @@ class SearchBuilder
2525 */
2626 protected array $ conditions = [];
2727
28- public function __construct (Model $ model )
28+ public function __construct (string | Model $ model )
2929 {
30+ if (is_string ($ model )) {
31+ $ model = new $ model ;
32+ }
33+
3034 $ this ->model = $ model ;
3135 }
3236
@@ -88,8 +92,7 @@ public function getQuery(): EloquentBuilder
8892
8993 return $ this ->query
9094 ->withExpression ('id_and_total_score ' , $ this ->getScoreQuery ())
91- ->leftJoin ('id_and_total_score ' , 'id_and_total_score.id ' , $ table .'.id ' )
92- ->whereRaw ($ table .'.id in (select id from id_and_total_score) ' )
95+ ->innerJoin ('id_and_total_score ' , $ table .'.id ' , 'id_and_total_score.id ' )
9396 ->orderBy ('score ' , 'desc ' );
9497 }
9598
Original file line number Diff line number Diff line change 99 expect ($ builder )->toBeInstanceOf (SearchBuilder::class);
1010});
1111
12+ test ('a search builder can be instanciated with a string class name ' , function () {
13+ $ builder = new SearchBuilder (FooModel::class);
14+
15+ expect ($ builder )->toBeInstanceOf (SearchBuilder::class);
16+ });
17+
1218test ('a model with the trait can get a configured search builder ' , function () {
1319 $ builder = FooModel::searchBuilder ();
1420
You can’t perform that action at this time.
0 commit comments