Download the PHP package ravaelles/filterable without Composer
On this page you can find all versions of the php package ravaelles/filterable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ravaelles/filterable
More information about ravaelles/filterable
Files in ravaelles/filterable
Package filterable
Short Description Package for handling record filtering in Laravel 5.*
License MIT
Homepage https://github.com/Ravaelles/Filterable
Informations about the package filterable
Filtering and searching Eloquent records for Laravel 5.*
Package to handle filtering of records in Laravel 5.*, ready to work with MongoDB.
Define filters easily. Save time by using provided bootstrap view which displays all the filters and properly styles select elements (and far more!). Oh, and there's also a nice search box, too! :)
Install
Via Composer
Usage
(1) Open config/app.php
and add to the end of providers this entry:
(2) Now open command line in root of your project and publish a view:
Feel free to modify it, it's now in resources\views\packages\filterable\filtering.blade.php
(3) Notice that filtering.blade.php
uses @push('scripts')
operator.
It appends all the javascript scripts to the end of the html, when jQuery has already been loaded to avoid jQuery is not defined
error.
To make it work, please add @stack('scripts')
part just after you load your last script using <script>
tag. Notice the @stack
blade operator is available since about Laravel 5.2.20.
(4) Now in your model add this trait:
Every model that you want to be filterable will need this trait.
(5) It's time to define filters to be used (variable $filters
). We will define some example filters so you can see how it works.
In your controller, just where you retrieve the records, add this:
Notice that you can apply your own, custom where
clauses just before the ->filterable
part.
(6) Finally, in your view add this line which will automatically display the filters using selects:
Feel free to modify this file as you wish.
(7) If you wish to use search box functionality then make sure to add ->searchable()
line in your controller like this:
...and in your model add a list of fields you want to search against e.g.
It will search for text from the search box in any of these fields.
(8) You are now able to use this package and dynamically filter the records! :)
License
The MIT License (MIT). Please see License File for more information.