9
9
use Illuminate \Database \Eloquent \Relations \HasOneOrMany ;
10
10
use Illuminate \Database \Eloquent \Relations \HasOneThrough ;
11
11
use Illuminate \Database \Eloquent \Relations \MorphTo ;
12
+ use Illuminate \Database \Eloquent \Relations \Relation ;
12
13
use Yajra \DataTables \Exceptions \Exception ;
13
14
14
15
/**
@@ -25,16 +26,12 @@ class EloquentDataTable extends QueryDataTable
25
26
*/
26
27
public function __construct ($ model )
27
28
{
28
- switch ($ model ) {
29
- case $ model instanceof Model:
30
- $ builder = $ model ->newQuery ();
31
- break ;
32
- case $ model instanceof EloquentBuilder:
33
- $ builder = $ model ;
34
- break ;
35
- default :
36
- throw new Exception ('Invalid model type. Must be an instance of Eloquent Model or Eloquent Builder. ' );
37
- }
29
+ $ builder = match (true ) {
30
+ $ model instanceof Model => $ model ->newQuery (),
31
+ $ model instanceof Relation => $ model ->getQuery (),
32
+ $ model instanceof EloquentBuilder => $ model ,
33
+ default => throw new Exception ('Invalid model type. Must be an instance of Eloquent Model, Eloquent Relation, or Eloquent Builder. ' ),
34
+ };
38
35
39
36
parent ::__construct ($ builder ->getQuery ());
40
37
@@ -100,10 +97,13 @@ protected function compileQuerySearch($query, string $column, string $keyword, s
100
97
}
101
98
102
99
if ($ this ->isMorphRelation ($ relation )) {
103
- $ query ->{$ boolean .'WhereHasMorph ' }($ relation , '* ' ,
100
+ $ query ->{$ boolean .'WhereHasMorph ' }(
101
+ $ relation ,
102
+ '* ' ,
104
103
function (EloquentBuilder $ query ) use ($ newColumn , $ keyword ) {
105
104
parent ::compileQuerySearch ($ query , $ newColumn , $ keyword , '' );
106
- });
105
+ }
106
+ );
107
107
} else {
108
108
$ query ->{$ boolean .'WhereHas ' }($ relation , function (EloquentBuilder $ query ) use ($ newColumn , $ keyword ) {
109
109
parent ::compileQuerySearch ($ query , $ newColumn , $ keyword , '' );
0 commit comments