PHPackages                             infinitypaul/laravel-database-filter - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Search &amp; Filtering](/categories/search)
4. /
5. infinitypaul/laravel-database-filter

ActiveLibrary[Search &amp; Filtering](/categories/search)

infinitypaul/laravel-database-filter
====================================

Need to filter database results with a query string? Here's a beautiful, easy to extend laravel package to keep your code super tidy.

5.0.0(10mo ago)2646.7k—2%4MITPHPPHP ^7.4|^8.0|^8.2CI passing

Since Apr 2Pushed 10mo ago3 watchersCompare

[ Source](https://github.com/infinitypaul/laravel-database-filter)[ Packagist](https://packagist.org/packages/infinitypaul/laravel-database-filter)[ Docs](https://github.com/infinitypaul/laravel-database-filter)[ RSS](/packages/infinitypaul-laravel-database-filter/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (10)Dependencies (3)Versions (15)Used By (0)

Laravel Database Filter
=======================

[](#laravel-database-filter)

[![Latest Version on Packagist](https://camo.githubusercontent.com/b5ebf4339f049697550451010f07ae5ff0ba36d3f56f549de186035a3747cec8/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f762f696e66696e6974797061756c2f6c61726176656c2d64617461626173652d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/infinitypaul/laravel-database-filter)[![Build Status](https://camo.githubusercontent.com/ecc8c16e7c864824e07ef307aafaa6d8cadd70cdfc9f433ce8010fb451bbed20/68747470733a2f2f696d672e736869656c64732e696f2f7472617669732f696e66696e6974797061756c2f6c61726176656c2d64617461626173652d66696c7465722f6d61737465722e7376673f7374796c653d666c61742d737175617265)](https://travis-ci.org/infinitypaul/laravel-database-filter)[![Quality Score](https://camo.githubusercontent.com/6e4ba878b3f3c09e5a2444de263ec5e6b5eb9df2139317693d168173ab0c8b4a/68747470733a2f2f696d672e736869656c64732e696f2f7363727574696e697a65722f672f696e66696e6974797061756c2f6c61726176656c2d64617461626173652d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://scrutinizer-ci.com/g/infinitypaul/laravel-database-filter)[![Total Downloads](https://camo.githubusercontent.com/86dcef3996e7d43007ea2aa6b0cda85235295642f2bfe7c55cb758c408ddc0a9/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f696e66696e6974797061756c2f6c61726176656c2d64617461626173652d66696c7465722e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/infinitypaul/laravel-database-filter)

Ever been stuck with filtering a database table with lots of GET parameters? I can only imagine how bulky your code will be. Relax, the easiest solution to this problem is right here. Let's say we have to query our records table with the following get parameters

> [https://www.example.com/records?dept=csc&amp;level=200&amp;grade=A](https://www.example.com/records?dept=csc&level=200&grade=A)

Installation
------------

[](#installation)

You can install the package via composer:

```
composer require infinitypaul/laravel-database-filter
```

The package will automatically register itself, but if your laravel versions is &lt; 5.5 you will need to add Infinitypaul\\LaravelDatabaseFilter\\LaravelDatabaseFilterServiceProvider::class, service provider under your config/app.php file.

Usage
-----

[](#usage)

Once the package is installed, an artisan command is available to you.

```
php artisan make:filter
```

We would be working with the records table below:

IdDepartmentLevelScoreGrade1csc20068b2physics10090a3csc10090a4physics20060b5csc20080aThe Filtering be done in 6 simple steps. Perfect right! Let's begin:

### \* Step 1

[](#-step-1)

Create a mother filter class, this is where all filters will be recorded. This can be created with this one line of code:

```
php artisan make:filter RecordFilter --model
```

This package will generate a new PHP file RecordFilter.php under app/Filters folder. This is where all other filters will be created.. It wil look like this

```
