DEV Community

Jefferson Silva
Jefferson Silva

Posted on

🔥 Laravel Query Gate v1.2.0 is AWESOME

API versioning is one of those topics everyone talks about…
and almost everyone implements in a painful way.

Multiple controllers.
Duplicated logic.
Hidden conditionals.
Broken clients.

Laravel Query Gate v1.2.0 introduces a different approach:

Version your API behavior at the query layer.

No boilerplate.
No magic.
No surprises.

🎯 The Problem With Traditional API Versioning

Most APIs evolve like this:

You change filters

You remove fields

You add sorting

You break someone’s integration

Even when using /v1/users and /v2/users, the real problem remains:

👉 Query behavior changes are scattered across the codebase.

Laravel Query Gate v1.2.0 centralizes this.

🧠 The Key Idea

Clients define the version they want:

X-Query-Version: 2026-01-05

The same endpoint adapts its behavior safely.

GET /query/users

No duplicated controllers.
No branching logic in services.

🧾 Built-in Changelog (Yes, Really)

Every versioned query automatically exposes a changelog endpoint:

GET /query/users/__changelog

Example response:

{
  "model": "App\\Models\\User",
  "alias": "users",
  "default": "2026-01-06",
  "active": "2026-01-05",
  "versions": [
    {
      "version": "2026-01-05",
      "changes": []
    },
    {
      "version": "2026-01-06",
      "changes": [
        "Removed filter: created_at",
        "Removed operator: created_at.gte",
        "Removed operator: created_at.lte",
        "Removed operator: created_at.between",
        "Removed select: created_at",
        "Added sort: name",
        "Added sort: email",
        "Added sort: created_at"
      ]
    }
  ]
}
Enter fullscreen mode Exit fullscreen mode

This means:

Instant API transparency

Easier debugging

Clear communication with frontend and integrations

🧩 The Code That Makes It Happen

Here’s a real example using Laravel Query Gate v1.2.0:

public static function queryGate(): QueryGate
{
    return QueryGate::make()
        ->alias('users')

        ->version('2026-01-05', function (QueryGate $qg) {
            return $qg->filters([
                'name' => 'string',
                'email' => 'email',
                'created_at' => 'date',
            ])
            ->allowedFilters([
                'name' => ['like'],
                'email' => ['eq', 'like'],
                'created_at' => ['gte', 'lte', 'between'],
            ])
            ->select(['id', 'name', 'email', 'created_at']);
        })

        ->version('2026-01-06', function (QueryGate $qg) {
            return $qg->filters([
                'name' => 'string',
                'email' => 'email',
            ])
            ->allowedFilters([
                'name' => ['like'],
                'email' => ['eq', 'like'],
            ])
            ->sorts(['name', 'email', 'created_at'])
            ->select(['id', 'name', 'email']);
        });
}

Enter fullscreen mode Exit fullscreen mode

What changed between versions?

created_at filter removed

Operators removed safely

Sorting added

Select fields adjusted

Old clients keep working

New clients get improvements

💡 Why This Is Powerful

Laravel Query Gate v1.2.0 gives you:

Explicit API contracts per version

Safe evolution without fear

One source of truth for queries

Less human error

Cleaner codebases

It treats API evolution as a first-class concern, not an afterthought.

🌐 Learn More

This is just one of the features.

👉 https://laravelquerygate.com

If you care about:

Maintainable APIs

Predictable behavior

Laravel-native solutions

You’ll feel right at home.

Feedback, ideas, and real-world edge cases are always welcome 🚀

Top comments (0)