2017 © Pedro Peláez
 

library laravel-query-builder

Easily build Eloquent queries from API requests

image

spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  • Tuesday, June 19, 2018
  • by Spatie
  • Repository
  • 24 Watchers
  • 817 Stars
  • 34,128 Installations
  • PHP
  • 4 Dependents
  • 1 Suggesters
  • 41 Forks
  • 8 Open issues
  • 35 Versions
  • 95 % Grown

The README.md

Build Eloquent queries from API requests

Latest Version on Packagist Test Status Code Style Status Total Downloads, (*1)

This package allows you to filter, sort and include eloquent relations based on a request. The QueryBuilder used in this package extends Laravel's default Eloquent builder. This means all your favorite methods and macros are still available. Query parameter names follow the JSON API specification as closely as possible., (*2)

Basic usage

Filter a query based on a request: /users?filter[name]=John:

use Spatie\QueryBuilder\QueryBuilder;

$users = QueryBuilder::for(User::class)
    ->allowedFilters('name')
    ->get();

// all `User`s that contain the string "John" in their name

Read more about filtering features like: partial filters, exact filters, scope filters, custom filters, ignored values, default filter values, ..., (*3)

Including relations based on a request: /users?include=posts:

$users = QueryBuilder::for(User::class)
    ->allowedIncludes('posts')
    ->get();

// all `User`s with their `posts` loaded

Read more about include features like: including nested relationships, including relationship count, custom includes, ..., (*4)

Sorting a query based on a request: /users?sort=id:

$users = QueryBuilder::for(User::class)
    ->allowedSorts('id')
    ->get();

// all `User`s sorted by ascending id

Read more about sorting features like: custom sorts, sort direction, ..., (*5)

Works together nicely with existing queries:

$query = User::where('active', true);

$userQuery = QueryBuilder::for($query) // start from an existing Builder instance
    ->withTrashed() // use your existing scopes
    ->allowedIncludes('posts', 'permissions')
    ->where('score', '>', 42); // chain on any of Laravel's query builder methods

Selecting fields for a query: /users?fields[users]=id,email

$users = QueryBuilder::for(User::class)
    ->allowedFields(['id', 'email'])
    ->get();

// the fetched `User`s will only have their id & email set

Read more about selecting fields., (*6)

Support us

, (*7)

We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products., (*8)

We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall., (*9)

Installation

You can install the package via composer:, (*10)

composer require spatie/laravel-query-builder

Read the installation notes on the docs site: https://spatie.be/docs/laravel-query-builder/v5/installation-setup., (*11)

Documentation

You can find the documentation on https://spatie.be/docs/laravel-query-builder/v5., (*12)

Find yourself stuck using the package? Found a bug? Do you have general questions or suggestions for improving the media library? Feel free to create an issue on GitHub, we'll try to address it as soon as possible., (*13)

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker., (*14)

Upgrading

Please see UPGRADING.md for details., (*15)

Testing

composer test

Changelog

Please see CHANGELOG for more information what has changed recently., (*16)

Contributing

Please see CONTRIBUTING for details., (*17)

Security

If you've found a bug regarding security please mail security@spatie.be instead of using the issue tracker., (*18)

Credits

License

The MIT License (MIT). Please see License File for more information., (*19)

The Versions

19/06 2018

dev-master

9999999-dev https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

12/06 2018

1.10.0

1.10.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

11/06 2018

1.9.6

1.9.6.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

09/06 2018

1.9.5

1.9.5.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

07/06 2018

1.9.4

1.9.4.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

05/06 2018

1.9.3

1.9.3.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

21/05 2018

1.9.2

1.9.2.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

21/05 2018

dev-analysis-q5OvRy

dev-analysis-q5OvRy https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

15/05 2018

1.9.1

1.9.1.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

02/05 2018

1.9.0

1.9.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

02/05 2018

dev-analysis-q1AV7j

dev-analysis-q1AV7j https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

02/05 2018

dev-gpibarra-master

dev-gpibarra-master https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

28/03 2018

1.8.0

1.8.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

23/03 2018

1.7.0

1.7.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

05/03 2018

1.6.0

1.6.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

05/03 2018

dev-analysis-qxpVGM

dev-analysis-qxpVGM https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

05/03 2018

dev-analysis-qgwM3d

dev-analysis-qgwM3d https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

10/02 2018

1.5.3

1.5.3.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

08/02 2018

1.5.2

1.5.2.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

07/02 2018

1.5.1

1.5.1.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

06/02 2018

1.5.0

1.5.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

05/02 2018

1.4.0

1.4.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

05/02 2018

1.3.0

1.3.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

03/02 2018

1.2.1

1.2.1.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

31/01 2018

dev-fix-scopes-and-other-builder-properties

dev-fix-scopes-and-other-builder-properties https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

30/01 2018

dev-feature-specific-exceptions

dev-feature-specific-exceptions https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

29/01 2018

1.2.0

1.2.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

23/01 2018

1.1.2

1.1.2.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

22/01 2018

1.1.1

1.1.1.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

20/01 2018

1.1.0

1.1.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

19/01 2018

1.0.1

1.0.1.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

17/01 2018

1.0.0

1.0.0.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

17/01 2018

0.0.3

0.0.3.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

17/01 2018

0.0.2

0.0.2.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder

16/01 2018

0.0.1

0.0.1.0 https://github.com/spatie/laravel-query-builder

Easily build Eloquent queries from API requests

  Sources   Download

MIT

The Requires

  • php ^7.1

 

The Development Requires

spatie laravel-query-builder