Download the PHP package myerscode/laravel-query-strategies without Composer

On this page you can find all versions of the php package myerscode/laravel-query-strategies. 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-strategies

Laravel Query Strategies

a package to help build queries with Eloquent Builder from URL parameters in a request

Latest Stable Version Total Downloads License

Why this package is helpful?

If you want to apply query clauses to Eloquent Models using parameters passed by the user, then this package will allow you to create strategies that will enable them to be applied automatically.

Using query strategies you can define what properties a user can have access to offering a safer way for them interact with your data schemas.

Strategies can obfuscate the real column names, add aliases to them and enable/disable the query clauses that can be applied to the model.

You can work the builder before and after applying a strategy, so it can be easily integrated with existing code and queries.

Installation

You can install the package via composer:

Applying strategies

Getting a filter instance by using one of the following methods:

Using the global helper

Use the facade

Building it yourself

Using the IsFilterable trait

You can then use the model itself to apply the filter

You can apply query filters, ordering, limits, includes, pagination.

Strategies

With strategies you can:

Strategy structure

$config

Fill in the $config property with the query parameters that you want use on the model.

$config should contain the allowed queries keys and the values aliases column default disabled methods

$defaultMethods

The $defaultMethods property contains all the clauses against an collection of aliases that properties can use.

Overriding this property will enable you to control what default methods a query can apply to a property of Model.

$limitTo

The $limitTo property sets what the default select limit is by default.

$maxLimit

The $maxLimit property sets what the max limit is, to help prevent people selecting all records form you database and degrading performance.

$orderBy

The $orderBy property is an array which sets what columns the Model can be ordered by.

Filters

By default parameters will have access to all the query filters in the $defaultMethods. You can create custom a Clause to do more complex or domain specific actions and add them to $defaultMethods or a single parameter.

Where Clauses

Type Aliases Query Eloquent
begins with beginsWith *% ?name[beginsWith]=Fr ?name[*%]=Fr Record::where('name', '=', 'Fr%')
contains contains %% ?name[contains]=Fr ?name[%%]=Fr Record::where('name', '=', '%Fr%')
ends with endsWith %* ?name[endsWith]=ed ?name[%*]=ed Record::where('name', '=', '%ed')
equals is = ?name=Fred ?name[is]=Fred ?name[is]=Fred Record::where('name', '=', 'Fred')
less than lessThan < lt ?hello[lessThan]=world ?hello[<]=world ?hello[lt]=world Record::where('hello', '<', 'world')
less than or equals lessThanOrEquals <= lte ?hello[lessThanOrEquals]=world ?hello[<=]=world ?hello[lte]=world Record::where('hello', '<=', 'world')
greater than greaterThan > gt ?hello[greaterThan]=world ?hello[>]=world ?hello[gt]=world Record::where('hello', '>', 'world')
greater than or equals greaterThanOrEquals >= gte ?hello[greaterThanOrEquals]=world ?hello[>=]=world ?hello[gte]=world Record::where('hello', '>=', 'world')
not equals not ! ?name[not]=Fred ?name[!]=Fred Record::where('hello', '!=', 'world')
is in isIn in ?name[isIn]=Fred,Tor ?name[in]=Fred,Tor ?name[]=Fred&name[]=Tor Record::whereIn('name', ['Fred', 'Tor'])
is not in notIn !in ?name[notIn]=Fred,Tor ?name[!in]=Fred,Tor Record::whereNotIn('name', ['Fred', 'Tor'])
or or || ?name[is]=Fred&name[or]=Tor Record::where('name', '=', 'Fred')->orWhere('name', '=', 'Tor')

Overriding the clause

You can use a special parameter to set a clause to all properties with that name in a query.

The following example would apply the not clause to the name properties.

By default the special parameter is $paramName with a default suffix of --operator. e.g. name--operator

The parameter can be either fully renamed or the suffix changed in the strategy config.

Properties with multiple values

If a property passed is found to be an array e.g. name[]=Fred&name[]=Tor&name[]=Chris then by default the IsInClause is used.

A property can be set to explode its values on a delimiter, so multiple values can be passed at once to a single parameter e.g. name=Fred,Tor,Chris. By default this is disabled and will need to be set on a property-by-property basis and is enabled by setting explode to true in the property config. The delimiter can be changed from the default , character using the delimiter config option.

Properties with clause in name

A property can be passed with its clause appended in the field name with -- as a separator.

?name--contains=ed

Ordering and Sorting

Sorting is ascending by default. The only available options for sorting is asc and desc - if a value other than those is past, it will resort to the default. ?order=name&sort=desc

?order[asc]=name&order[desc]=id

Limiting

?limit=10

?order[asc]=name&order[desc]=id

Using the config

Run the publish command, to create the config file in /config

This will create config/query-strategies.php which contains the default settings for things such as reserved parameter keys (limit, page, with etc.)

Creating a new strategy

To quickly create a new Strategy class in Queries/Strategies run:

Creating a new query clause

To quickly create a new Clause class in Queries/Clause run:

License

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


All versions of laravel-query-strategies with dependencies

PHP Build Version
Package Version
Requires php Version ^8.1
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 myerscode/laravel-query-strategies contains the following files

Loading the files please wait ....