PHPackages                             johannesschobel/dingoquerymapper - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. johannesschobel/dingoquerymapper

ActiveLibrary

johannesschobel/dingoquerymapper
================================

Uses Dingo/API Request Query Parameters to filter Laravel Models

1226.1k6[6 issues](https://github.com/johannesschobel/dingoquerymapper/issues)[1 PRs](https://github.com/johannesschobel/dingoquerymapper/pulls)PHP

Since May 6Pushed 7y ago1 watchersCompare

[ Source](https://github.com/johannesschobel/dingoquerymapper)[ Packagist](https://packagist.org/packages/johannesschobel/dingoquerymapper)[ RSS](/packages/johannesschobel-dingoquerymapper/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (1)Used By (0)

dingo-query-mapper
==================

[](#dingo-query-mapper)

Uses Dingo/API Request Query Parameters to filter Laravel Collections. For example, you are able to automatically filter, sort, and limit collections based on query parameters of the URI.

Installation
============

[](#installation)

First, add the respective line to your composer file

```
"require" : {
   ... ,
   "johannesschobel/dingoquerymapper": "dev-master" ,
}
```

and run `composer install` to install the new component.

Then add respective `ServiceProvider` from the package to your `config/app.php` configuration file, like this:

```
'providers' => [
   ... ,
   JohannesSchobel\DingoQueryMapper\DingoQueryMapperServiceProvider::class,
],
```

If you want, you can overwrite the basic configuration using the following command:

```
php artisan vendor:publish --provider="JohannesSchobel\DingoQueryMapper\DingoQueryMapperServiceProvider" --tag="config"
```

This will copy the `dingoquerymapper` configuration file to your `config` folder. Using this file, you can customize the `limit` parameter or the query parameters to be excluded from the service provider. This is handy, if you need to omit parameters from automatically parsed for filtering (e.g., you may want to exclude the `token` parameter if you are using `JWT`).

Usage
=====

[](#usage)

Example
-------

[](#example)

In order to use the plugin, simply create a new instance from `DingoQueryMapper` and pass the request. Furthermore, you want to call respective `createFromXXX()` method from the `DingoQueryMapper`, which basically allows to create the mapper from various inputs (e.g., `Collection`, `Builder`, ...)

Consider the following example:

```
public function getAllUsers(Request $request) {

    $users = User::all()->get();
    $qm = new DingoQueryMapper($request);
    $users = $qm->createFromCollection($users)->paginate();

    // now return the result
    return response->json($users);
}
```

If you call the respective URI, for example like so:

```
/index?name=j*&age>=18&limit=10&page=3
```

it will output (a maximum of) `10 User`s per page, where the `name` attribute starts with `j` and the `age` is greater or equal than `18` starting on `page 3`.

Dingo/API Example
-----------------

[](#dingoapi-example)

If you use [Dingo/API](https://github.com/dingo/api) as your preferred API framework, you can use this package right away. If you are not using Dingo/API, you should really consider using it - it is awesome!

However, all of the information described above still remains when using Dingo/API. Only, the returning the results varies because you need to use Dingo's response objects.

You can simply return your results using

```
public function getAllUsers(Request $request) {

    $users = User::all()->get();
    $qm = new DingoQueryMapper($request);
    $users = $qm->createFromCollection($users)->paginate();

    // now return the result

    return $this->response
       ->paginator($users, new UserTransformer());
}
```

That's all - really!

Parameters
----------

[](#parameters)

This plugin provides some pre-defined parameter names to be automatically filled.

### `limit` and `page`

[](#limit-and-page)

In order to limit the amount of response elements, simply add respective `limit` query parameter, like this:

```
/index?limit=20
```

This will only return the (first) `20` entries of the result. In order to request the next `20` entries, simply add a `page` parameter to the query, like this:

```
/index?limit=20&page=2
```

will return the next `20` entries that are located on `page 2`.

### `sort`

[](#sort)

In order to sort the results using different parameters, you can simply concatenate them using `,`. In order to provide `ASC` and `DESC` sorting, you may prepend a `-` before respective attribute. Sorting is case-insensitive.

For example

```
/index?sort=age,-name
```

sorts the results by age (ascending), then by name (descending; note the `-` before the `name` field!)

### `custom filters`

[](#custom-filters)

Of course you may pass custom query parameters to the builder in order to `filter` the requested data. For example:

- `name=j*` : filters all elements, where the name starts with `j`,
- `age>=18` : filters all elements, where the age is `18` or higher,
- `city!=berlin` : filters all elements, where the city is not `berlin`

If you try to filter using a column that does not exist in the respective model, it will be ignored.

At the moment, this plugin offers the following operators:

- `=` --&gt; compare equality
- `!=` --&gt; compare unequality
- `` --&gt; greater than

Of course you can combine the filters with the other query parameters:

```
/index?name=j*&age>=18&sort=age,-name&limit=20
```

would return the first `20` elements, where the `name` starts with `j`, the `age` is `>= 18`sorted by `age ASC` and `name DESC`.

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance10

Infrequent updates — may be unmaintained

Popularity35

Limited adoption so far

Community14

Small or concentrated contributor base

Maturity37

Early-stage or recently created project

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/554f30f3c24b34c1961da6f12c0e2cfec6436e1c6dd6b8092669a7138086d770?d=identicon)[johannesschobel@googlemail.com](/maintainers/johannesschobel@googlemail.com)

---

Top Contributors

[![simondotwhite](https://avatars.githubusercontent.com/u/793770?v=4)](https://github.com/simondotwhite "simondotwhite (6 commits)")[![johannesschobel](https://avatars.githubusercontent.com/u/9431350?v=4)](https://github.com/johannesschobel "johannesschobel (5 commits)")[![sgtwinters](https://avatars.githubusercontent.com/u/14836040?v=4)](https://github.com/sgtwinters "sgtwinters (1 commits)")[![youkoulayley](https://avatars.githubusercontent.com/u/2247492?v=4)](https://github.com/youkoulayley "youkoulayley (1 commits)")

### Embed Badge

![Health badge](/badges/johannesschobel-dingoquerymapper/health.svg)

```
[![Health](https://phpackages.com/badges/johannesschobel-dingoquerymapper/health.svg)](https://phpackages.com/packages/johannesschobel-dingoquerymapper)
```

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
