New

Just launched: Vueblocks, a brand-new search engine for Vue packages! Explore Vueblocks →

jwohlfert23/laravel-api-query

Provides laravel scope to build query from request query params
17,179
Install
composer require jwohlfert23/laravel-api-query
Latest Version:v6.1.2
PHP:^8.2
Laravel:11 · 12 · 13
Older releases:6 – 10
License:MIT
Last Updated:Jul 1, 2026
Links: GitHub  ·  Packagist
Maintainer: jwohlfert23

Build Eloquent Queries from Request Query Params

Installation

composer require jwohlfert23/laravel-api-query

Usage

This package is implemented as a trait, which provides the buildFromRequest scope.

use Jwohlfert23\LaravelApiQuery\BuildQueryFromRequest;

class Post {
    use BuildQueryFromRequest;
}
Post::buildFromRequest()->get();
?sort=-id,name

is the same as:

Post::orderByDesc('id')->orderBy('name');
?filter[name]=Bobby&filter[author.name][contains]=Bob

is the same as:

Post::where('name', 'Bobby')->whereHas('author', function($q) {
    $q->where('name', 'like', '%Bob%');
});

Note: this package doesn't use "whereHas", but rather performs left joins internally. However, the results should be the same as the above code.

Filters default to using the "equal" operator. These are the operators available to use in filtering (contains is use above).

  • eq (=)
  • gt (>)
  • gte (>=)
  • lt (<)
  • lte (<=)
  • contains
?with=author,comments

is the same as

Post::with('author','comments');

Related Packages

railken/lara-eye
38,923 38
api
juampi92/api-resources

Manage your resources maintaining API versioning

934,590 112
tailflow/laravel-orion

Orion for Laravel allows you to build a fully featured REST API based on your El...

814,907 1,591
unlu/laravel-api-query-builder

Laravel API Query Builder Package.

720,803 329
juampi92/phecks

A package to run custom PHP checks

411,917 4

Version History

Version Released PHP Laravel License
v6.1.2 ^8.2 ^11.0|^12.0|^13.0 MIT
v6.1.1- ^8.2 ^11.0|^12.0|^13.0 MIT
6.1.0 ^8.2 ^11.0|^12.0|^13.0 MIT
6.0.2 ^8.2 ^11.0|^12.0 MIT
6.0.1 ^8.2 ^11.0|^12.0 MIT