88
99class DataTableService
1010{
11-
1211 protected array $ allowedFilters ;
12+
1313 protected array $ allowedRelations ;
14+
1415 protected array $ allowedSortings ;
16+
1517 protected array $ allowedSelects ;
18+
1619 private int $ totalRowCount ;
1720
1821 public function __construct (
19- protected Builder $ query ,
22+ protected Builder $ query ,
2023 private DataTableInput $ dataTableInput
21- )
22- {
24+ ) {
2325 }
2426
2527 public function setAllowedFilters (array $ allowedFilters ): DataTableService
2628 {
2729 $ this ->allowedFilters = $ allowedFilters ;
30+
2831 return $ this ;
2932 }
3033
3134 public function setAllowedRelations (array $ allowedRelations ): DataTableService
3235 {
3336 $ this ->allowedRelations = $ allowedRelations ;
37+
3438 return $ this ;
3539 }
3640
3741 public function setAllowedSortings (array $ allowedSortings ): DataTableService
3842 {
3943 $ this ->allowedSortings = $ allowedSortings ;
44+
4045 return $ this ;
4146 }
4247
4348 public function setAllowedSelects (array $ allowedSelects ): DataTableService
4449 {
4550 $ this ->allowedSelects = $ allowedSelects ;
51+
4652 return $ this ;
4753 }
4854
4955 /**
5056 * Handle 'getData' operations
51- * @return array
5257 */
5358 public function getData (): array
5459 {
5560 $ query = $ this ->buildQuery ();
5661 $ data = $ query ->get ();
5762
58- return array (
63+ return [
5964 'data ' => $ data ,
6065 'meta ' => [
61- 'totalRowCount ' => $ this ->totalRowCount
62- ]
63- ) ;
66+ 'totalRowCount ' => $ this ->totalRowCount ,
67+ ],
68+ ] ;
6469 }
6570
6671 protected function buildQuery (): Builder
@@ -78,18 +83,19 @@ protected function buildQuery(): Builder
7883
7984 $ query ->offset ($ this ->dataTableInput ->getStart ());
8085
81- if (! is_null ($ this ->dataTableInput ->getSize ())){
86+ if (! is_null ($ this ->dataTableInput ->getSize ())) {
8287 $ query ->limit ($ this ->dataTableInput ->getSize ());
8388 }
8489
8590 $ sorting = $ this ->dataTableInput ->getSorting ();
8691 $ query = (new ApplySort ($ query , $ sorting ))->apply ();
92+
8793 return $ query ;
8894 }
8995
9096 protected function applySelect (Builder $ query , array $ selectedFields ): Builder
9197 {
92- if (!empty ($ selectedFields )) {
98+ if (! empty ($ selectedFields )) {
9399 $ query ->select ($ selectedFields );
94100 }
95101
@@ -98,7 +104,7 @@ protected function applySelect(Builder $query, array $selectedFields): Builder
98104
99105 protected function includeRelationsInQuery (Builder $ query , array $ rels ): Builder
100106 {
101- if (!empty ($ rels )) {
107+ if (! empty ($ rels )) {
102108 $ query ->with ($ rels );
103109 }
104110
0 commit comments