File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change 32
32
*/
33
33
'disable_invalid_filter_query_exception ' => false ,
34
34
35
+ /*
36
+ * By default the package will throw an `InvalidSortQuery` exception when a sort in the
37
+ * URL is not allowed in the `allowedSorts()` method.
38
+ */
39
+ 'disable_invalid_sort_query_exception ' => false ,
40
+
35
41
/*
36
42
* By default the package inspects query string of request using $request->query().
37
43
* You can change this behavior to inspect the request body using $request->input()
Original file line number Diff line number Diff line change @@ -85,7 +85,7 @@ protected function addRequestedSortsToQuery()
85
85
86
86
$ sort = $ this ->findSort ($ key );
87
87
88
- $ sort ->sort ($ this , $ descending );
88
+ $ sort? ->sort($ this , $ descending );
89
89
});
90
90
}
91
91
@@ -99,6 +99,10 @@ protected function findSort(string $property): ?AllowedSort
99
99
100
100
protected function ensureAllSortsExist (): void
101
101
{
102
+ if (config ('query-builder.disable_invalid_sort_query_exception ' )) {
103
+ return ;
104
+ }
105
+
102
106
$ requestedSortNames = $ this ->request ->sorts ()->map (function (string $ sort ) {
103
107
return ltrim ($ sort , '- ' );
104
108
});
Original file line number Diff line number Diff line change 136
136
->allowedSorts ('id ' );
137
137
});
138
138
139
+ it ('does not throw invalid sort query exception when disable in config ' , function () {
140
+ config (['query-builder.disable_invalid_sort_query_exception ' => true ]);
141
+
142
+ createQueryFromSortRequest ('name ' )
143
+ ->allowedSorts ('id ' );
144
+
145
+ expect (true )->toBeTrue ();
146
+ });
147
+
139
148
test ('an invalid sort query exception contains the unknown and allowed sorts ' , function () {
140
149
$ exception = InvalidSortQuery::sortsNotAllowed (collect (['unknown sort ' ]), collect (['allowed sort ' ]));
141
150
You can’t perform that action at this time.
0 commit comments