spatie / laravel-query-builder

Easily build Eloquent queries from API requests

Home Page:https://spatie.be/docs/laravel-query-builder

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Request parameters are not handled for sort/filter requests

renepardon opened this issue · comments

I implemented an action like this: https://gist.github.com/renepardon/162334dfbd4c208b9090fffeda9dbaff
Based on lorisleiva/laravel-actions .

The passed $request object is of type Illuminate\Http\Request and contains the following data from UI/Frontend:

array:2 [
  "sort" => "-name"
  "filter" => array:1 [
    "search" => "asdf"
  ]
]

My problem here is that the -name filter is not applied, it's always name as defined within defaultSort and neither the scope nor the callback filters are being called, ever.

Versions in use

"laravel/framework": "^8.65",
"laravel/jetstream": "^2.5",
"laravel/sanctum": "^2.11",
"laravel/scout": "^9.3",
"lorisleiva/laravel-actions": "^2.2",
"spatie/laravel-query-builder": "^4.0",

I tried reproducing the error with your given example but for me, it does call the custom filter and print the debug output.

Did you pass the name twice? Once for sorting and once for filtering? In my case the query parameters look like this:

?sort=-name&filter[name]=dominik&filter[search]=developer

Dear contributor,

because this issue seems to be inactive for quite some time now, I've automatically closed it. If you feel this issue deserves some attention from my human colleagues feel free to reopen it.