jwohlfert23/laravel-api-query

Provides laravel scope to build query from request query params
16,596
Install
composer require jwohlfert23/laravel-api-query
Latest Version:v6.1.2
PHP:^8.2
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

illuminatech/data-provider

Allows easy build for DB queries from API requests

14,952 44
bjerke/api-query-builder

A query builder for Laravel that parses the request and uses Eloquent ORM to que...

7,822 26
sheikhheera/requent

A GraphQL like interface to map a request to eloquent query with data transforma...

171 78
ghost202/laravel-api-query-builder

Forked, Laravel API Query Builder Package.

1 0
bjerke/laravel-bread

A boilerplate package for BREAD operations through REST API in Laravel

5,221 11