Making the advanced search query with Eloquent-Builder in Laravel
Fouladgar.dev
Posted on September 5, 2018
We needed an advanced search system in the recent project. This system included many filters that required a flexible and scalable search system.
I decided to implement a package for this system that you can see it in the GitHub and use it in your project.
What's the problem?
The problem is that you will encounter with a set of filters that you must check for a lot of conditions to add to the query.
Writing a lot of terms will surely reduce the readability of your code and slow down the development process.
Also, you can only use the filters and terms in the same scope and they will not be reusable.
But the Solution
You must Refactor your code!
To solve this problem, you need to Refactor your code by replacing many of your conditionals with Polymorphism.
Click here to learn more about this design pattern.
Practical Example:
Suppose we want to get the list of the users with the requested parameters as follows:
This package provides an advanced filter for Laravel model based on incoming requets.
Provides a Eloquent query builder for Laravel
This package allows you to build eloquent queries, based on incoming request parameters. It greatly reduces the complexity of the
queries and conditions, which will make your code clean and maintainable.
Version Compatibility
Laravel
EloquentBuilder
11.0.x
5.x.x
10.0.x
4.2.x
9.0.x
4.0.x
6.0.x to 8.0.x
3.0.x
5.0.x
2.2.2
Basic Usage
Suppose you want to get the list of the users with the requested parameters as follows: