2017 © Pedro Peláez
 

library filterable

A laravel package for working with query filtering

image

hugorut/filterable

A laravel package for working with query filtering

  • Sunday, December 20, 2015
  • by hugorut
  • Repository
  • 1 Watchers
  • 1 Stars
  • 13 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 0 Forks
  • 0 Open issues
  • 2 Versions
  • 0 % Grown

The README.md

Build Status, (*1)

Fiterable

A package which provides a fluent interface to apply constraints to an Eloquent query, (*2)

For example:, (*3)

#Set the package to run all constraints against an Article model
$filter = Filter::setType('articles');

#filter those articles by the Page and Author model so that only
#articles that appear with these contraints are returned
$filter->only([
    'pages' => [1, 2], 
    'authors' => [4, 7, 9]
])->get();

Installation

First, pull in the package through Composer., (*4)

composer require hugorut/filterable

Include the service provider within config/app.php., (*5)

'providers' => [
    Hugorut\Filter\Laravel\FilterServiceProvider::class,
];

Add the facade alias to this same file at the bottom:, (*6)

'aliases' => [
    'Filter'    => Hugorut\Filter\Laravel\Filter::class,
];

Then publish the package assets by running in your project root, (*7)

php artisan vendor:publish

You should see a terminal output similar to:, (*8)

Copied File [/vendor/Filter/src/Hugorut/Filter/config.php] To [/config/filter.php]
Publishing complete for tag []!

Usage

Config, (*9)

First you need to provide the package with knowledge of what models are filterable and which can have filters applied to them. Add your settings to the package configuration file which located at app\config\filter.php after you have published the package assets., (*10)

Add models you wish to apply filters to in the Builders array, (*11)

'Builders' => [
    'articles' => 'App\Article'
],

Add models you wish to filter by in the Filters array, (*12)

'Filters' => [
    'pages' => 'App\Page',
    'authors' => 'App\Author'
],

API, (*13)

It is highly recommended that you use the Filter facade or dependency injection to access the package functionality as this the class has a number of depencies which the laravel IOC container can rectify., (*14)

Using the Filter class is simple, first set a model you wish to appy filters against (and which has been aliased in the filter config file)., (*15)

$filter = Filter::setType('articles');

Now the filter is configured to the correct model you can call either the only or the without methods on the filter., (*16)

$filter->only(['pages' => [1, 2]]);
/*-----
* or
-----*/
$filter->without(['pages' => [1, 2]]);

The parameters of both of these methods are an assoicative array. The keys of this associative array are the model aliases (as defined in your app\config\filter.php config file) and the values are an array of the ids of these models., (*17)

Call the get method on the filter to then query the database and return the filtered results., (*18)

$filter->get();

The Versions

20/12 2015

dev-master

9999999-dev https://github.com/hugorut/filterable

A laravel package for working with query filtering

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

orm laravel eloquent

06/12 2015

0.0.1

0.0.1.0 https://github.com/hugorut/filterable

A laravel package for working with query filtering

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

The Development Requires

orm laravel eloquent