PHPackages                             behindsolution/laravel-query-gate - 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. behindsolution/laravel-query-gate

ActiveLibrary[API Development](/categories/api)

behindsolution/laravel-query-gate
=================================

Generic HTTP gateway for Laravel Eloquent queries.

v1.7.0(3mo ago)50603MITPHPPHP ^8.2

Since Dec 27Pushed 3mo ago4 watchersCompare

[ Source](https://github.com/behindSolution/laravel-query-gate)[ Packagist](https://packagist.org/packages/behindsolution/laravel-query-gate)[ RSS](/packages/behindsolution-laravel-query-gate/feed)WikiDiscussions main Synced today

READMEChangelog (10)Dependencies (16)Versions (43)Used By (0)

Laravel Query Gate
==================

[](#laravel-query-gate)

[![Latest Version](https://camo.githubusercontent.com/76d653f2c8f5db7f9e72d98f56e1b02a70d66aafeff6c0fd8ab9a7035ed4b010/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f626568696e64736f6c7574696f6e2f6c61726176656c2d71756572792d676174652e737667)](https://packagist.org/packages/behindsolution/laravel-query-gate)[![Tests](https://github.com/behindSolution/QueryGate/actions/workflows/tests.yml/badge.svg)](https://github.com/behindSolution/QueryGate/actions/workflows/tests.yml)[![Total Downloads](https://camo.githubusercontent.com/bd2291aa7d52c43a647ba4c7155e97b0f1c9a9f899bb1cdfc72a7ccdee859063/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f626568696e64736f6c7574696f6e2f6c61726176656c2d71756572792d676174652e737667)](https://packagist.org/packages/behindsolution/laravel-query-gate)[![License](https://camo.githubusercontent.com/2fda68e663e2fed16a1765d6611733292f5a9b1861f3765d0e797c7e95734b1d/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f6c2f626568696e64736f6c7574696f6e2f6c61726176656c2d71756572792d676174652e737667)](LICENSE)

A declarative API layer for Laravel that turns Eloquent models into fully featured REST endpoints — with filtering, sorting, actions, versioning, OpenAPI docs, and a type-safe TypeScript SDK.

Features
--------

[](#features)

- **Declarative API definition** — define filters, sorts, selects, and actions directly on your model
- **CRUD actions** — built-in create, update, delete, and detail with validation, policies, and custom handlers
- **Custom actions** — extend your API with reusable action classes
- **API versioning** — version your endpoints with automatic changelog generation
- **OpenAPI documentation** — auto-generated spec and UI out of the box
- **TypeScript code generation** — generate type-safe contracts with `php artisan qg:types`
- **Frontend SDK** — fully typed, framework-agnostic query builder for the frontend
- **Caching &amp; pagination** — cursor and offset pagination, built-in cache support

Requirements
------------

[](#requirements)

- PHP 8.2+
- Laravel 10, 11, or 12

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

[](#installation)

```
composer require behindsolution/laravel-query-gate
```

Publish the config file:

```
php artisan vendor:publish --tag=query-gate-config
```

Quick Start
-----------

[](#quick-start)

Add the trait to your model and define the query gate:

```
use BehindSolution\LaravelQueryGate\Traits\HasQueryGate;
use BehindSolution\LaravelQueryGate\Support\QueryGate;

class User extends Model
{
    use HasQueryGate;

    public static function queryGate(): QueryGate
    {
        return QueryGate::make()
            ->alias('users')
            ->select(['id', 'name', 'email', 'created_at'])
            ->filters(['name' => 'string', 'email' => 'email'])
            ->allowedFilters(['name' => ['like', 'eq'], 'email' => ['eq']])
            ->sorts(['name', 'created_at']);
    }
}
```

Your API is ready:

```
GET    /query/users?filter[name][like]=John&sort=-created_at
GET    /query/users/1

```

Actions
-------

[](#actions)

Define mutations with a fluent builder:

```
QueryGate::make()
    ->alias('posts')
    ->actions(fn ($actions) => $actions
        ->create(fn ($action) => $action
            ->validations(['title' => 'required|string', 'body' => 'required|string'])
            ->policy('create')
        )
        ->update(fn ($action) => $action
            ->validations(['title' => 'string', 'body' => 'string'])
            ->policy('update')
        )
        ->delete(fn ($action) => $action->policy('delete'))
        ->detail()
    );
```

Custom actions:

```
->actions(fn ($actions) => $actions
    ->use(PublishPostAction::class)
)
```

API Versioning
--------------

[](#api-versioning)

```
QueryGate::make()
    ->alias('users')
    ->version('2024-01-01', fn ($gate) => $gate
        ->select(['id', 'name', 'email'])
        ->filters(['name' => 'string'])
    )
    ->version('2024-06-01', fn ($gate) => $gate
        ->select(['id', 'name', 'email', 'avatar'])
        ->filters(['name' => 'string', 'email' => 'email'])
    );
```

Clients select a version via the `X-Query-Version` header or `?version=` query parameter. A changelog is auto-generated at `GET /query/users/__changelog`.

TypeScript Code Generation
--------------------------

[](#typescript-code-generation)

Generate type-safe contracts from your API definitions:

```
php artisan qg:types --output=resources/ts/contracts
```

Output example:

```
export interface UserEntity {
  id: number;
  name: string;
  email: string;
}

export interface UserCreatePayload {
  name: string;
  email: string;
}

export interface UserResourceContract {
  get: UserEntity;
  create: { payload: UserCreatePayload; response: UserEntity };
  // ...
}
```

Frontend SDK
------------

[](#frontend-sdk)

Install the companion SDK:

```
npm install laravel-query-gate-sdk
```

```
import { configureQueryGate, queryGate } from 'laravel-query-gate-sdk'

configureQueryGate({ baseUrl: 'https://api.example.com/query' })

// List with filters and sorting
const users = await queryGate('users')
  .filter('name', 'like', 'John')
  .sort('created_at', 'desc')
  .get()

// Create
await queryGate('users')
  .post({ name: 'Jane', email: 'jane@example.com' })

// Update
await queryGate('users').id(1)
  .patch({ name: 'Jane Doe' })

// Custom action
await queryGate('posts').id(1)
  .action('publish').post()
```

OpenAPI Documentation
---------------------

[](#openapi-documentation)

Enable in `config/query-gate.php`:

```
'openAPI' => [
    'enabled' => true,
],
```

Access the generated docs at `GET /query/docs` (UI) or `GET /query/docs.json` (spec).

Ecosystem
---------

[](#ecosystem)

- [Documentation](https://laravelquerygate.com)
- [Example Project](https://github.com/behindSolution/LQG-example)
- [Frontend SDK](https://github.com/behindSolution/laravel-query-gate-sdk)
- [Discord Community](https://discord.gg/ydFBEZ8aTD)

Contributing
------------

[](#contributing)

Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for details.

License
-------

[](#license)

MIT

###  Health Score

46

—

FairBetter than 92% of packages

Maintenance81

Actively maintained with recent releases

Popularity21

Limited adoption so far

Community11

Small or concentrated contributor base

Maturity60

Established project with proven stability

 Bus Factor1

Top contributor holds 100% 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 ~2 days

Recently: every ~16 days

Total

39

Last Release

101d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/45333690?v=4)[Jefferson T.S](/maintainers/jeffleyd)[@jeffleyd](https://github.com/jeffleyd)

---

Top Contributors

[![jeffleyd](https://avatars.githubusercontent.com/u/45333690?v=4)](https://github.com/jeffleyd "jeffleyd (107 commits)")

---

Tags

apicruddslfastapilaravelphprest

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/behindsolution-laravel-query-gate/health.svg)

```
[![Health](https://phpackages.com/badges/behindsolution-laravel-query-gate/health.svg)](https://phpackages.com/packages/behindsolution-laravel-query-gate)
```

###  Alternatives

[psalm/plugin-laravel

Psalm plugin for Laravel

3355.3M346](/packages/psalm-plugin-laravel)[api-platform/laravel

API Platform support for Laravel

58171.5k14](/packages/api-platform-laravel)[laravel/cashier

Laravel Cashier provides an expressive, fluent interface to Stripe's subscription billing services.

2.6k29.9M146](/packages/laravel-cashier)[roots/acorn

Framework for Roots WordPress projects built with Laravel components.

9762.4M131](/packages/roots-acorn)[pressbooks/pressbooks

Pressbooks is an open source book publishing tool built on a WordPress multisite platform. Pressbooks outputs books in multiple formats, including PDF, EPUB, web, and a variety of XML flavours, using a theming/templating system, driven by CSS.

45444.2k1](/packages/pressbooks-pressbooks)[fleetbase/core-api

Core Framework and Resources for Fleetbase API

1235.9k20](/packages/fleetbase-core-api)

PHPackages © 2026

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