Download the PHP package ahoysolutions/query-filters without Composer
On this page you can find all versions of the php package ahoysolutions/query-filters. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ahoysolutions/query-filters
More information about ahoysolutions/query-filters
Files in ahoysolutions/query-filters
Package query-filters
Short Description A Laravel package to filter database queries based on the query string.
License MIT
Informations about the package query-filters
Query Filters
Installation
Step 1: Composer
From the command line, run:
Step 2: Service Provider
From within your Laravel application, open config/app.php
and within the providers
array, add:
This will bootstrap the package into Laravel for you.
Usage
Adding a filters class to a model
You can add a filter class through artisan command, just like with controllers, models, or other similar resources. For example, assuming you wanted to leverage filters on your Post model, you might use:
Afterwards, a new query filter class will be added to your directory.
Adding filter methods
To add a filter method to an filter class, simply add a function to the class. For example, assume you have an incoming request with a query string that looks like .
Your filters class might then look like this:
Filtering for an query string array
Imagine your user wants to search based on an array of different tags, for example:
As you can see, you don't have to do anything within the filter to allow the user to leverage this functionality.
The relevant query filter will then be called multiple times and apply the filter for each tag. This is good for checking against many-to-many relationships.
Adding sortable methods
You can specify that a field should be sortable by calling $this->resetOrderBy()
before leveraging the builder, for example:
If you have multiple sortables, the latest one leveraged by the user will take precedence.
Credits
- Inspired by Laracasts (https://laracasts.com/series/lets-build-a-forum-with-laravel)
- Originally developed by Chris Sorrells on behalf of Ahoy Solutions, LLC.
All versions of query-filters with dependencies
illuminate/http Version ^5.4
illuminate/database Version ^5.4
illuminate/console Version ^5.4
illuminate/support Version ^5.4