Download the PHP package kyslik/laravel-filterable without Composer

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

Laravel Filterable

Latest Version on Packagist Build Status Total Downloads

This package allows you to easily handle database filtering through query strings. The idea is taken from one of the Jeffrey's videos (behind the paywall). One quick example might look like this: /users?filter-username=~joe will result in SQL query select * from users where "username" like '%joe%'.

Installation

You can install the package via composer:

If you are using Laravel 7:

Laravel will discover the package by itself. If you feel old-school, disable auto-discovery and add Kyslik\LaravelFilterable\FilterableServiceProvider::class to the providers array in your config/app.php.

You may continue by publishing configuration by issuing following artisan command php artisan vendor:publish.

Introduction

Package lets you to create && apply two kinds of filters custom and generic.

Custom filters

Custom filters are just like in Jeffrey's video. You define a logic on a builder instance and package applies it via local scope.

Let's say a product requires displaying recently created records. You create a method recent($minutes = null) inside a filter class, which returns Builder instance:

Note: full example is shown later on

Generic filters

Generic filters are those defined in config file. By default, the package supports filtering timestamps, ranges, ins, booleans and strings.

Default operator matrix for generic filters

operator accepts description
= string equal
!= string not equal
> string greater than
< string less than
>= string equal or greater than
<= string equal or less than
~ string like
!~ string not like
>< comma separated list between
!>< comma separated list not between
i= comma separated list in
i!= comma separated list not in
b= 1, 0, true, false, yes, no equal
b!= 1, 0, true, false, yes, no not equal
t= UNIX timestamp equal
t!= UNIX timestamp not equal
t> UNIX timestamp greater than
t< UNIX timestamp less than
t>= UNIX timestamp equal or greater than
t<= UNIX timestamp equal or less than
t>< UNIX timestamp between
t!>< UNIX timestamp not between

Usage

While using both custom or generic filters you must:

  1. have local scope on model with the signature scopeFilter(Builder $query, FILTERNAME $filters)
  2. have particular (FILTERNAME) filter class that extends one of:
    • Kyslik\LaravelFilterable\Generic\Filter class - allows usage of both custom & generic filters
    • Kyslik\LaravelFilterable\Filter class - allows usage of only custom filters
  3. call a scope within a controller

make:filter command

You can use the following command to create a new filter.

This will create a new Custom filter in the app/Filters directory. To create a Generic filter just add the --generic (-g) flag to the command:

Lastly, you can override the default namespace by changing the namespace config value e.g.

config/filterable.php

Example with custom filters

Let's say you want to use filterable on User model. You will have to create the filter class App/Filters/UserFilter.php (php artisan make:filter UserFilter), specify filterMap() and filter method (recent(...)) with the custom logic.

Note: filterMap() shall return an associative array where key is a method name and value is either alias or array of aliases

Now add a local scope to the User model via Filterable:

Finally, call the scope in a controller like so:

Now end-user can visit users?recent or users?recently or users?recent=25 and results will be filtered by recent() method defined in UserFilter class.

Example with generic filters

Let's say you want to use generic filters on User model. You will have to create filter class App/Filters/UserFilter.php (php artisan make:filter UserFilter -g) and specify $filterables just like below:

Next, you will have to add a local scope to the User model via Filterable:

Finally, call the scope in a controller like so:

Now you are ready to filter User model.

Note: behind the scenes ...\Generic\Filter class extends Filter class, therefore using ...\Generic\Filter also enables you to apply custom filters defined within the filter class

Additional configuration

While using generic filters you may define which generics should be allowed. Define settings() method in a filter class, see below:

Additional features

Default filtering

In case you need to apply a filter when no filter is applied yet (determined by what query-string contains at the given request), you can use the following code in the controller:

End-user is going be redirected from http://filters.test/users to http://filters.test/users?recent=2018-10-01 13:52:40&filter-id=!=5. In case the filter that you specify as default does not exist Kyslik\LaravelFilterable\Exceptions\InvalidArgumentException is thrown.

Caution: be careful of infinite redirects

You can read more about the feature in the original issue #10.

JoinSupport for filters

TBA

You can read more about the feature in the original PR #9.

Testing

Changelog

Please see CHANGELOG for more information what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email [email protected] instead of using the issue tracker.

Credits

License

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


All versions of laravel-filterable with dependencies

PHP Build Version
Package Version
Requires php Version >=7.1
illuminate/support Version 5.6.*|5.7.*|5.8.*
illuminate/database Version 5.6.*|5.7.*|5.8.*
illuminate/http Version 5.6.*|5.7.*|5.8.*
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 kyslik/laravel-filterable contains the following files

Loading the files please wait ....