Download the PHP package infinitypaul/laravel-database-filter without Composer

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

Laravel Database Filter

Latest Version on Packagist Build Status Quality Score Total Downloads

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&level=200&grade=A

Installation

You can install the package via composer:

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

Usage

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

We would be working with the records table below:

Id Department Level Score Grade
1 csc 200 68 b
2 physics 100 90 a
3 csc 100 90 a
4 physics 200 60 b
5 csc 200 80 a

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

* 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:

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

* Step 2:

Since we are working with the records table, we will be working on the Record model. So open your Record model and include the following:

* Step 3:

We would be filtering with 3 parameters (dept, level, grade):

Let's create filter classes for each filter

The above commands will also generate a new PHP file under app/Filters folder with the name DebtFilter.php, LevelFilter.php and GradeFilter.php which will look like below.

Well Done!!! Let's move to the next step

* Step 4:

Now we write our logic in each class:

In our DeptFilter class, we write the following:

In our LevelFilter class, we write the following:

In our GradeFilter class, we write the following:

The filter method takes in our conditions or whatever checks against the database

Bravo on completing that. Moving on!!!

* Step 5:

We write our search parameters against the filter class. Let's open up our mother filter class - RecordFilter to register all the conditions we have generated.

The $Filter array key is will be the query params.

* Step 6:

Assuming we have a controller RecordController, we can create a function to get our record:

We are all done!!!

When we enter the following into our browser

https://www.example.com/records?dept=csc&level=200&grade=a

We will get the following result:

Tweak Time

To be strict about query params input, we can use the mapping method or leave empty for free entry.

Let's say when returning the data, we want all department with csc to return as CSC. We return values to the mappings function in the DeptFilter class as shown below:

With the above setup, once csc is entered in your query params, it will return CSC as value.

Lastly, You can add local scoped filter() by passing an array of filter into the filter scope.

You can also override your filter property from your controller in this manner

So instead of your filter to use the RecordFilter it will make use of PaulFilter

Bug & Features

If you have spotted any bugs, or would like to request additional features from the library, please file an issue via the Issue Tracker on the project's Github page: https://github.com/infinitypaul/laravel-database-filter/issues.

Contributing

Please see CONTRIBUTING for details.

Security

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

How can I thank you?

Why not star the github repo? I'd love the attention! Why not share the link for this repository on Twitter or HackerNews? Spread the word!

Don't forget to follow me on twitter!

Thanks! Edward Paul.

License

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


All versions of laravel-database-filter with dependencies

PHP Build Version
Package Version
Requires php Version ^7.4|^8.0
illuminate/contracts Version ^7.0|^8.0|^9.0|^10.0|^11.1
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 infinitypaul/laravel-database-filter contains the following files

Loading the files please wait ....