Download the PHP package acodingproject/laravel-filterable without Composer

On this page you can find all versions of the php package acodingproject/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:

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.

Before we start

Package lets us create & apply two kinds of filters: custom and generic.

Custom filters

Custom filters are just like in Jeffrey's video. We define our logic on builder instance and package will apply it via local scope.
Let's say we want to display recently created records. We create method recent($minutes = null) inside our filter class, this method returns Builder instance:

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 we must:

  1. have local scope on model with signature scopeFilter(Builder $query, FILTERNAME $filters)
  2. have particular (FILTERNAME) filter class that extends one of:
    • Kyslik\LaravelFilterable\GenericFilterable class - enables us to use both custom & generic filters
    • Kyslik\LaravelFilterable\Filterable class - enables us to use only custom filters
  3. call scope within a controller

Example with custom filters

Let's say we want to use filterable on user model. We will have to create filter class App/Filters/UserFilter.php, specify filterMap() and method with our custom logic.

Note: filterMap() must be defined and it should return associative array where key is method name and value is either alias or array of aliases

Secondly, we will have to add a local scope to our user model via trait:

Finally, in user controller we will have to call model's scope:

Now we can visit users?recent or users?recently or users?recent=25 and results will be filtered by recent() method defined in UserFilters class.

Example with generic filters

Let's say we want to use filterable on user model. We will have to create filter class App/Filters/UserFilter.php and specify $filterables.

Secondly, we will have to add a local scope to our user model via trait:

Finally, in our user controller we will have to call model's scope:

We are ready to filter user model.

Note: behind the scenes GenericFilterable class extends Filterable class, thus using GenericFilterable also enables us to apply custom filters defined within the filter class

Additional configuration

While using generic filters we may define which generics should be allowed. In our filter class we define settings() method in which we specify settings.

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 8.*
illuminate/support Version 8.*|9.*|10.*
illuminate/database Version 8.*|9.*|10.*
illuminate/http Version 8.*|9.*|10.*
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 acodingproject/laravel-filterable contains the following files

Loading the files please wait ....