PHPackages                             thejawker/laravel-interrogator - 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. thejawker/laravel-interrogator

ActiveLibrary[API Development](/categories/api)

thejawker/laravel-interrogator
==============================

Interrogates the request and applies JSON API rules to the Laravel Query Builder.

0.1.1(5y ago)45421[3 PRs](https://github.com/thejawker/laravel-interrogator/pulls)MITPHPPHP ~7.4|^8.0

Since Mar 20Pushed 3y ago1 watchersCompare

[ Source](https://github.com/thejawker/laravel-interrogator)[ Packagist](https://packagist.org/packages/thejawker/laravel-interrogator)[ Docs](https://github.com/thejawker/laravel-interrogator)[ RSS](/packages/thejawker-laravel-interrogator/feed)WikiDiscussions master Synced yesterday

READMEChangelog (10)Dependencies (3)Versions (15)Used By (0)

Just Ask, And We'll Get It For You
==================================

[](#just-ask-and-well-get-it-for-you)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b68269da19a4b79532f2e1a79f39209e9f32200124d74465bc597078d7b2dfbb/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f7468656a61776b65722f6c61726176656c2d696e746572726f6761746f722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/thejawker/laravel-interrogator)

Installation
------------

[](#installation)

Require the package from Composer:

```
composer require thejawker/laravel-interrogator
```

Usage
-----

[](#usage)

You can `interrogate()` any Laravel Model in a Controller. Basic setup is easy peasy but does not provide proper security. Security can be added where needed.

```
// App/Http/Controllers/UserController.php

// GET: /users?filter[name]=john*&sort=-name
// Returns the Users where the name starts with John and is sorted DESC by name.
public function get() {
    return interrogate(User::class)->get();
}
```

### Filtering

[](#filtering)

You can use filters to add where clauses to your query builder. A filter is depicted by the `filter[column]=value` variable.

#### Wildcard Filter

[](#wildcard-filter)

You can use wildcard operators in string filters. It is possible to create fairly complex filters this way.

```
GET http://example.com/api/sites?filter[url]=https*/thejawker/posts/*/images
```

#### List Filter

[](#list-filter)

A comma-seperated list can be used as a filter. This will in turn run a `whereIn` on the `QueryBuilder`.

```
GET http://example.com/api/user?files[type]=jpg,png
```

> Note that you can currently **not** combine this with the wildcard filter as follows: `jpg,pn*`.

#### And or Or

[](#and-or-or)

You can specify the select's `and` or `or` conditions.

For example if you want to fetch `Users` with a gmail email address **AND** and a Dutch mobile phone numbers, you could do the following.

```
GET http://example.com/api/users?filter[email]=*gmail*&filter[phone]=[and]+31*
```

By default the `or` operator is used, however you are free to explicitly

```
GET http://example.com/api/users?filter[email]=*gmail*&filter[phone]=[or]+31*
```

#### Math Operations

[](#math-operations)

It is possible to use a variety of different math operators in a filter.

OperatorMath OperatorNameExamplege&gt;=Greater or equalfilter\[price\]=\[ge\]500gt&gt;Greater thanfilter\[price\]=\[gt\]500le&lt;=Less or equalfilter\[price\]=\[le\]500lt&lt;Less thanfilter\[price\]=\[lt\]500Of course you can combine this with the **And or Or** operator.

#### Default filters

[](#default-filters)

It is possible to conveniently set default filters on the Interrogator. These can be overriden by the api consumer (client). Under the hood it will set the filter to the request.

```
interrogate(User::class)
    ->defaultFilters(['email' => '*@gmail.com'])
    ->get();
```

If you want you can filter the QueryBuilder beforehand as well.

```
interrogate(User::whereType('admin'))
    ->get();
```

#### Null Filter

[](#null-filter)

Sometimes you need to make sure a column is null. You can for example do the following:

```
GET http://example.com/api/users?filter[profile_image]=[null]
```

#### Security

[](#security)

For some models you might want to prevent filtering on certain columns. The way you do this is by allowing a selection of fields. A not allowed filter will throw an error.

```
public function get() {
    return interrogate(User::class)
        ->allowFilters(['email', 'name'])
        ->get();
}
```

> NOTE: nested filters are currently not supported.

### Sorting

[](#sorting)

Sorting works according to the JSON spec by using the `sort` parameter on the request with the column name as a value.

You can sort by **asc**:

```
GET http://example.com/api/users?sort=name
```

You can also sort by **descending** by adding a hyphen `-`:

```
GET http://example.com/api/users?sort=-name
```

#### Security

[](#security-1)

Like filtering there's some security baked in to the package. You can allow certain sorting columns by adding `->allowSortBy(['email'])` onto the Interrogator.

```
interrogate(User::query())
    ->request($request)
    ->allowSortBy(['email'])
    ->get();
```

#### Default sorting

[](#default-sorting)

Also default sorting can be defined on the `Interrogator`. Like the filtering; this is added on the request.

```
public function get() {
    return interrogate(User::class)
        ->defaultSortBy('-email')
        ->get();
}
```

Chain shortcuts
---------------

[](#chain-shortcuts)

You can keep chaining on with the Interrogator. `Pagination` and `get` are made shortcuts allowing you to do the following.

```
// Gets all the results from the database.
interrogate(User::class)->get();

// Paginates the results using the Laravel paginator.
interrogate(User::class)->paginate();

// Gets the query on the Interrogator, you are
// then free to work with it like expected.
interrogate(User::class)->query()->take(2);
```

Your Life Made Easy
-------------------

[](#your-life-made-easy)

The `interrogate()` helper function tries to make your life easier by allowing various types. We try to solve your intent when you enter one of the following types.

```
// Illuminate\Database\Eloquent\Builder
interrogate(User::query());

// Illuminate\Database\Eloquent\Builder
interrogate(User::whereAdmin(true));

// Illuminate\Database\Eloquent\Relations\Relation;
interrogate(User::first()->posts());

// Class contstant
interrogate(User::class);
```

Alternatives
------------

[](#alternatives)

For everything is a really nice [Spatie package](https://github.com/spatie/laravel-query-builder). I needed to be able to do some math specific operations that were not supported in the mentioned package.

Test
----

[](#test)

```
composer test
```

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

32

—

LowBetter than 72% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity18

Limited adoption so far

Community10

Small or concentrated contributor base

Maturity66

Established project with proven stability

 Bus Factor1

Top contributor holds 91.3% of commits — single point of failure

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 ~99 days

Recently: every ~179 days

Total

11

Last Release

1988d ago

PHP version history (4 changes)0.0.1PHP ^7.0

0.0.9PHP ~7.2

0.1.0PHP ~7.4

0.1.1PHP ~7.4|^8.0

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/6703837?v=4)[Bram Veerman](/maintainers/thejawker)[@thejawker](https://github.com/thejawker)

---

Top Contributors

[![thejawker](https://avatars.githubusercontent.com/u/6703837?v=4)](https://github.com/thejawker "thejawker (21 commits)")[![a-schuurman](https://avatars.githubusercontent.com/u/7899502?v=4)](https://github.com/a-schuurman "a-schuurman (2 commits)")

---

Tags

thejawkerinterrogatorlaravel-interrogatorJSON API Laravel Query Builder

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/thejawker-laravel-interrogator/health.svg)

```
[![Health](https://phpackages.com/badges/thejawker-laravel-interrogator/health.svg)](https://phpackages.com/packages/thejawker-laravel-interrogator)
```

###  Alternatives

[stripe/stripe-php

Stripe PHP Library

4.0k143.3M480](/packages/stripe-stripe-php)[twilio/sdk

A PHP wrapper for Twilio's API

1.6k92.9M272](/packages/twilio-sdk)[knplabs/github-api

GitHub API v3 client

2.2k15.8M187](/packages/knplabs-github-api)[facebook/php-business-sdk

PHP SDK for Facebook Business

90121.9M34](/packages/facebook-php-business-sdk)[meilisearch/meilisearch-php

PHP wrapper for the Meilisearch API

73813.7M114](/packages/meilisearch-meilisearch-php)[google/gax

Google API Core for PHP

263103.1M454](/packages/google-gax)

PHPackages © 2026

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