Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

freshface's avatar

URL/Request parameters to query

I want to provide query params in my url to filter in my database. fe: /api/books?_q=The Lord of the Rings&_sort=-_score I found this package https://github.com/marcelgwerder/laravel-api-handler

But I was wondering if there are any other packages out there with will do the same and are better maintained.

The one I am referring to doesn't allow filtering on joined tables.

0 likes
6 replies
jlrdw's avatar

You can do that already out of the box, querystring.

freshface's avatar

Yes but then I have to parse the query string and convert it to eloquent or a raw sql query?

I was wondering if there was a package to do this that could handle this.

jlrdw's avatar

I guess I don't follow, you can get the querystring using

$request->input('whatever');

Right now so

$book = $request->input('The Lord of the Ring');

Sorry if I don't understand

freshface's avatar

Yes, I know how to get the query string. But if you I was wondering I there is a package that handles the query string to eloquent with the correct filteren, sorting, ...

Querstring > Generated eloquent

See the first post for link.

jlrdw's avatar

Yes I see how the package works. I was just saying if you did not want a package it's just a little work to do yourself, a multi-search type form.

Edit, Like

$query = Dog::where('dogname', 'like', $dogsch);
        if ($aval == "n") {
            $query->where('adopted', '=', 1);
        } else if ($aval == "y") {
            $query->where('adopted', '=', 0);
        }
       $dogs = $query->orderBy('lastedit', 'DESC')->paginate(5);

I simply get the request and query for available dogs, or view ones already adopted, or if blank view all.

Please or to participate in this conversation.