@@ -35,7 +35,11 @@ public function response(?Builder $queryOrModel = null): DatatableResource
3535 ->fromRequest ();
3636
3737 // Attempt to always get a query builder
38- $ baseQuery = $ this ->resolveQueryOrModel ($ queryOrModel );
38+ if ($ queryOrModel !== null ) {
39+ $ this ->withQuery ($ queryOrModel );
40+ }
41+
42+ $ baseQuery = $ this ->getQuery ();
3943
4044 /** @var Model|Searchable $model */
4145 $ model = $ baseQuery ->getModel ();
@@ -49,10 +53,12 @@ public function response(?Builder $queryOrModel = null): DatatableResource
4953 function (Builder $ query ) use ($ baseQuery ) {
5054 $ query
5155 // Select columns
52- ->select ($ this ->getColumnKeys ()->toArray ())
56+ // TODO: check if we can resolve columns to select in a smarter way
57+ //->select($this->getColumnKeys()->toArray())
5358
5459 // Merge previous query
5560 ->mergeConstraintsFrom ($ baseQuery )
61+ ->setEagerLoads ($ baseQuery ->getEagerLoads ())
5662
5763 // Perform sorting
5864 ->when ($ this ->data ->hasSorting (), function (Builder |ScoutBuilder $ subQuery ) {
@@ -100,6 +106,19 @@ function (Builder $query) use ($baseQuery) {
100106 // Dispatch the action
101107 $ this ->dispatchAction ();
102108
103- return (new DatatableResource ($ paginator ))->rightSideMaximumPages (3 );
109+ $ response = (new DatatableResource ($ paginator ));
110+
111+ // Ensure we can transform the data that is being displayed
112+ if (method_exists ($ this , 'transform ' )) {
113+ $ response ->transformResponseUsing (fn ($ record ) => $ this ->transform ($ record ));
114+ }
115+
116+ // Ensure we can transform the data that is being displayed
117+ $ pagination = 3 ;
118+ if (property_exists ($ this , 'paginationItems ' )) {
119+ $ pagination = $ this ->paginationItems ;
120+ }
121+
122+ return $ response ->rightSideMaximumPages ($ pagination );
104123 }
105124}
0 commit comments