Download the PHP package nycu-csit/laravel-query-builder without Composer

On this page you can find all versions of the php package nycu-csit/laravel-query-builder. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package laravel-query-builder

Laravel Query Builder

This package makes you to filter, sort, include, count eloquent model easily based on the query string from the request.

QueryBuilder

NycuCsit\LaravelQueryBuilder\QueryBuilder extends laravel query builder and supports fluent interface, you can use any laravel query builder function call on it.

Filtering

The filter query parameters can be used to add where clauses to your Eloquent query. Only allowed query parameters could be parsed and built as a SQL query. If the query parameters is not allowed, it will be skipped without any error.

The supported format of query string:

Use QueryBuilder to parse query string and build query:

The SQL query of GET /users?year[gt]=2022 will be look like this:

Add many allowed query parameter filters:

Use add() to add allowed query parameter filter:

Operators

Operator Meaning Value String Number Boolean Datetime Date Time
eq Equals to Any
neq Not equals to Any
gt Greater than Any
lt Less then Any
ge Greater or equals to Any
le Less or equals to Any
in Equals to one of array Comma-seperated value
notin Not equals to one of array Comma-seperated value
is Is null or notnull
like Like (SQL fuzzy string) string
year_eq Year equals to number
month_eq Month equals to number
day_eq Day equals to number
date_eq Date equals to date string (RFC3339)
time_eq Date equals to time string (RFC3339)

If there aren't a specified [operator] , the query builder will use the default operator you specified. By default, the operator is eq.

Query Scope

The scope query parameters can be used to apply a Query Scope to your Eloquent query. Only allowed scope could be parsed and built as a SQL query. If the scope is not allowed, it will be skipped without any error.

Supports these format of query string:

For example, you may define a scope function:

Use allowedScopes() in the query builder:

The query string

will be applied as $query->banned().

The arguments will be passed by corresponding names, the order does not affect. If the arguments doesn't fit the scope function's definition, this scope query string will be ignored.

Argument Transformer

You may check or modify the arguments array in the transformer. The transformer could be an array of callables or single callable, the array transformer will be invoked one by one.

The scope query builder will send the arguments in the query string of the scope to the transformers.

Here is the query string:

the arguments of scope 'ofCondition' is:

You may use Cast as transformer to cast string to other type in the arguments:

Or, you can just use a closure as transformer:

Filtering Existence

The filter query parameters with existence operators can be used to add has() clauses to your Eloquent query. The not allowed query parameters will be skipped without any error.

The supported format of query string:

Use QueryBuilder to parse query string and build query:

The SQL query of GET /users?filter[posts][exist]=true will be look like this:

Add many allowed query parameter existence filters:

Use add() to add allowed query parameter existence filter:

Operators

Operator Meaning Value
exist Have at least one related record bool
exist_eq Number of related records equals to number
exist_neq Number of related records not equals to number
exist_gt Number of related records greater than number
exist_lt Number of related records less then number
exist_ge Number of related records greater or equals to number
exist_le Number of related records less or equals to number

Including relationships

The include query parameter will load any Eloquent relation or relation count on the resulting models. All includes must be explicitly allowed using allowedIncludes().

The supported format of query string:

Use QueryBuilder to parse query string and build query:

The SQL query of GET /users?include=posts will be look like this:

Be caution, you should call allowedIncludes or add(AllowedIncludes...) only once per query, because including validation will be added in future version.

The corresponding shorthand for add() is NycuCsit\LaravelQueryBuilder\Criteria\AllowedIncludes.

Sorting

The sort query parameter is used to determine by which property the results' collection will be ordered. Sorting is ascending by default and can be reversed by adding a hyphen (-) to the start of the property name.

If there is any not allowed parameter in sort query parameter, an Illuminate\Validation\ValidationException will be thrown.

The supported format of query string:

Use QueryBuilder to parse query string and build query:

The SQL query of GET /users?sort=create_time,-email will be look like this:

The corresponding shorthand for add() is NycuCsit\LaravelQueryBuilder\Criteria\AllowedSorts.

Counting relationship

The count query parameter will count on the related records. All counts must be explicitly allowed using allowedCounts().

The supported format of query string:

Use QueryBuilder to parse query string and build query:

The SQL query of GET /users?count=posts will be look like this:

As you can see, there is a new field news_posts_count is appended, but the field name will be<relationName>_count instead of <parameterName>_count.

The corresponding shorthand for add() is NycuCsit\LaravelQueryBuilder\Criteria\AllowedCounts.

Extra Queries for single Model

Eager Loading

Sometimes, we want to load relationships for a model by query string. Just use HasExtraQuery trait in your model class:

The supported format of query string:

Now, you can use allowedLoad() function on your model:

The query string &load[author]=1 will be applied as $post->load('user').

The allowedLoad() function supports fluent interface.


All versions of laravel-query-builder with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
laravel/framework Version ^10.0|^11.0|^12.0|^13.0
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package nycu-csit/laravel-query-builder contains the following files

Loading the files please wait ...