@@ -31,14 +31,17 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = [])
3131 foreach ($ this ->repository ->getMatchByFields () as $ key => $ type ) {
3232 $ negation = false ;
3333
34- if (! $ request ->has ($ key ) && ! data_get ($ extra , "match. $ key " )) {
34+ if ($ request ->has ('- ' . $ key )) {
35+ $ negation = true ;
36+ }
37+
38+ if (!$ request ->has ($ negation ? '- ' . $ key : $ key ) && !data_get ($ extra , "match. $ key " )) {
3539 continue ;
3640 }
3741
38- $ match = $ request ->input ($ key , data_get ($ extra , "match. $ key " ));
42+ $ match = $ request ->input ($ negation ? ' - ' . $ key : $ key , data_get ($ extra , "match. $ key " ));
3943
40- if (substr ($ key , 0 , 1 ) === '- ' ) {
41- $ negation = true ;
44+ if ($ negation ) {
4245 $ key = Str::after ($ key , '- ' );
4346 }
4447
@@ -49,7 +52,11 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = [])
4952 $ field = $ model ->qualifyColumn ($ key );
5053
5154 if ($ match === 'null ' ) {
52- $ query ->whereNull ($ field );
55+ if ($ negation ) {
56+ $ query ->whereNotNull ($ field );
57+ } else {
58+ $ query ->whereNull ($ field );
59+ }
5360 } else {
5461 switch ($ this ->repository ->getMatchByFields ()[$ key ]) {
5562 case RestifySearchable::MATCH_TEXT :
@@ -69,7 +76,7 @@ public function prepareMatchFields(RestifyRequest $request, $query, $extra = [])
6976 case RestifySearchable::MATCH_INTEGER :
7077 case 'number ' :
7178 case 'int ' :
72- $ query ->where ($ field , $ negation ? '!= ' : '= ' , (int ) $ match );
79+ $ query ->where ($ field , $ negation ? '!= ' : '= ' , (int )$ match );
7380 break ;
7481 case RestifySearchable::MATCH_DATETIME :
7582 $ query ->whereDate ($ field , $ negation ? '!= ' : '= ' , $ match );
@@ -107,7 +114,7 @@ public function prepareOrders(RestifyRequest $request, $query, $extra = [])
107114 }
108115
109116 if (empty ($ params ) === true ) {
110- $ this ->setOrder ($ query , '+ ' . $ this ->repository ->newModel ()->getKeyName ());
117+ $ this ->setOrder ($ query , '+ ' . $ this ->repository ->newModel ()->getKeyName ());
111118 }
112119
113120 return $ query ;
@@ -151,7 +158,7 @@ public function prepareSearchFields(RestifyRequest $request, $query, $extra = []
151158 $ likeOperator = $ connectionType == 'pgsql ' ? 'ilike ' : 'like ' ;
152159
153160 foreach ($ this ->repository ->getSearchableFields () as $ column ) {
154- $ query ->orWhere ($ model ->qualifyColumn ($ column ), $ likeOperator , '% ' . $ search. '% ' );
161+ $ query ->orWhere ($ model ->qualifyColumn ($ column ), $ likeOperator , '% ' . $ search . '% ' );
155162 }
156163 });
157164
@@ -204,12 +211,12 @@ public function setOrder($query, $param)
204211
205212 protected function applyIndexQuery (RestifyRequest $ request , Repository $ repository )
206213 {
207- return fn ($ query ) => $ repository ::indexQuery ($ request , $ query ->with ($ repository ::$ with ));
214+ return fn ($ query ) => $ repository ::indexQuery ($ request , $ query ->with ($ repository ::$ with ));
208215 }
209216
210217 protected function applyFilters (RestifyRequest $ request , Repository $ repository , $ query )
211218 {
212- if (! empty ($ request ->filters )) {
219+ if (!empty ($ request ->filters )) {
213220 $ filters = json_decode (base64_decode ($ request ->filters ), true );
214221
215222 collect ($ filters )
@@ -235,7 +242,7 @@ protected function applyFilters(RestifyRequest $request, Repository $repository,
235242 return $ matchingFilter ;
236243 })
237244 ->filter ()
238- ->each (fn (Filter $ filter ) => $ filter ->filter ($ request , $ query , $ filter ->value ));
245+ ->each (fn (Filter $ filter ) => $ filter ->filter ($ request , $ query , $ filter ->value ));
239246 }
240247
241248 return $ query ;
0 commit comments