Skip to content

Commit 8b2a0b3

Browse files
committed
add filter and order array root key
1 parent 4336bb8 commit 8b2a0b3

File tree

3 files changed

+32
-2
lines changed

3 files changed

+32
-2
lines changed

src/Config/queryextend.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,28 @@
6464
|
6565
*/
6666
"base_query_parent_class" => "Classid\LaravelQueryBuilderExtend\Contracts\Abstracts\BaseQueryBuilder",
67+
68+
69+
/*
70+
|--------------------------------------------------------------------------
71+
| Array key name for query param grouping on filter
72+
|--------------------------------------------------------------------------
73+
|
74+
| When you using filterColumn you will receive request with grouping array
75+
| set to null if you don't want to use this array key
76+
|
77+
*/
78+
"filter_query_param_root" => "filter",
79+
80+
81+
/*
82+
|--------------------------------------------------------------------------
83+
| Array key name for query param grouping on order
84+
|--------------------------------------------------------------------------
85+
|
86+
| When you using orderColumn you will receive request with grouping array
87+
| set to null if you don't want to use this array key
88+
|
89+
*/
90+
"order_query_param_root" => "order",
6791
];

src/Traits/QueryFilter.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,9 @@ private function getRelationDBColumn(string $relationName, string $requestedKey)
251251
*/
252252
private function setRequestQueryParam(): self
253253
{
254-
$this->requestQueryParam = request()->query();
254+
$this->requestQueryParam = config("queryextend.filter_query_param_root") ?
255+
request()->query(config("queryextend.filter_query_param_root"), []) :
256+
request()->query();
255257

256258
return $this;
257259
}

src/Traits/QueryOrder.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ public function _orderColumn(array|string|null $orderableColumns = null, string
1818
$this->defaultOrderColumn();
1919

2020
if (is_array($orderableColumns)) {
21-
$requestQueryParam = request()->query();
21+
$requestQueryParam = config("queryextend.order_query_param_root") ?
22+
request()->query(config("queryextend.order_query_param_root"), []) :
23+
request()->query();
24+
25+
2226
$columns = array_intersect_key($requestQueryParam, $orderableColumns);
2327

2428
foreach ($columns as $columnName => $requestDirection) {

0 commit comments

Comments
 (0)