Download the PHP package ambengers/query-filter without Composer

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

Laravel Query Filter

This packages provides an elegant way to filter your eloquent models via the request query string.

Inspired by Laracasts

Build Status StyleCI

Features

This packages allows you to create filters via the request query string. Out of the box, this package also features sorting, pagination and search for your eloquent models.

Installation

Run the following command in the terminal.

Then publish the config file by running the following command.

The config file contains the configuration for the namespace and path of the filter classes. The default namespace is App\Filters and default path is app/Filters.

Usage

Method-based Filters

You can generate a filter class using the make:query-filter command.

In the filter class, you can also define your own custom filters. For example, lets add a filter for /posts?published to get only the published posts:

Now, you can apply the filter on your controller. For example:

Object-based Filters

If you like a more object oriented approach for creating your filters, you can create a $filters array in your Filter class to declare your filters.

$filters array will receive a key-value pair in which the key is the param in your query string and the value is the filter object that will handle the filtering.

Then you can use the make:query-filter-object command to generate your filter object. Note: filter objects will use the same namespace as your filter class.

The filter object is a simple invokable class that accepts the Eloquent\Builder as first parameter and the query string value as the second parameter. Include the filter logic in the invoke method, like so.

Sorting

This package also allows you to sort your models by following field|direction syntax, like so.

Pagination

This package also allows you to paginate your models like so.

Behind the scenes, it uses Laravel's own pagination, which the default per_page size is 15. Of course, you can override this behaviour like so.

Note: If pagination keys are not present on the request query string, it will return a collection result.

Search

This package also allows you to define the columns that are searchable. By default, when you generate a filter class with make:query-filter command, the class will contain a $searchableColumns array. Then, list the searchable columns of your model in this array.

Searchable Relationship Columns

The $searchableColumns can also accept a key value pair if you want your model to be searchable using relationship fields:

Loadable Relationships

This packages allows you to load relationships of models using the query string. First, use the make:query-loader command to create your loader class.

Then, declare the loader class within your filter class.

Then on the loader class, declare the relationships that can be eager/lazy-loaded within $loadables array.

And that's it! Now use the load param on your query string to load relationships.

Note: Relationships with multiple words can be declared using either camel or snake case within the $loadables array. The package will automatically convert the relationships into snake case which is typically how you will write your relationship methods. Also, relationships that are not declared in $loadables array will not be eager-loaded even if used in query string.

Using Loader On The Controller@show Action

Controller@show action will typically return a single model instance instead of a collection. However, there are cases that you will need an ability to optionally load relationships via query string as well.

Inject your loader class as an argument to your show method, then call the filter method on your and pass the loader instance.

Now you should be able to load your relationships from your query string.

Including Soft Delete Constraints

Include soft deleted constraits when requesting for eager loaded models using the pipe symbol.

Preventing Method Name Clash

To customize the method name you call on your model to use the query filter, just update the value of the method key in the query_filter config file.

With Laravel Livewire

Livewire follows its own structure when sending requests to the backend. This makes it impossible for query-filter package to automatically read parameters from the request query string.

However, you can still manually assign parameters during runtime by resolving your query filter class from the container and set the parameters like so...

Similar Packages

cerbero90/query-filters


All versions of query-filter with dependencies

PHP Build Version
Package Version
No informations.
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 ambengers/query-filter contains the following files

Loading the files please wait ....