PHPackages                             parsadp/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. [API Development](/categories/api)
4. /
5. parsadp/dingoquerymapper

ActiveLibrary[API Development](/categories/api)

parsadp/dingoquerymapper
========================

Uses Dingo/API Request Query Parameters to filter Laravel Models

1.0.1(5y ago)046MITPHPPHP &gt;=5.5.0

Since Oct 10Pushed 5y agoCompare

[ Source](https://github.com/parsadp/dingoquerymapper)[ Packagist](https://packagist.org/packages/parsadp/dingoquerymapper)[ RSS](/packages/parsadp-dingoquerymapper/feed)WikiDiscussions master Synced 2d ago

READMEChangelog (1)Dependencies (1)Versions (3)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" : {
   ... ,
   "parsadp/dingoquerymapper": "^1.0.1" ,
}
```

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

24

—

LowBetter than 32% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity8

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity50

Maturing project, gaining track record

 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.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2040d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/40893271?v=4)[ParsaDP](/maintainers/parsadp)[@parsadp](https://github.com/parsadp)

---

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)")[![bitcodr](https://avatars.githubusercontent.com/u/10177380?v=4)](https://github.com/bitcodr "bitcodr (2 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)")

---

Tags

query-stringapilaraveldingo

### Embed Badge

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

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

###  Alternatives

[darkaonline/l5-swagger

OpenApi or Swagger integration to Laravel

2.9k34.0M112](/packages/darkaonline-l5-swagger)[knuckleswtf/scribe

Generate API documentation for humans from your Laravel codebase.✍

2.3k12.2M45](/packages/knuckleswtf-scribe)[dingo/blueprint

API Blueprint documentation generator.

2707.8M22](/packages/dingo-blueprint)[nilportugues/laravel5-json-api-dingo

Laravel5 JSONAPI and Dingo together to build APIs fast

311.5k](/packages/nilportugues-laravel5-json-api-dingo)

PHPackages © 2026

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