DEV Community

Discussion on: Making the advanced search query with Eloquent-Builder in Laravel

Collapse
 
redon92 profile image
Redon

Seriously? Imagine if you have 15-20 filters, you will repeat the queries with if loop 20 times?

Collapse
 
mohammadfouladgar profile image
Fouladgar.dev

I think it's better than using complex terms. In this way we have better management of each filter.

Also, We observation to the single responsibility principle.

if you have a better way, please suggest. thanks a lot for your notice.

Collapse
 
redon92 profile image
Redon

You can build the query with normal mysql syntax, then if you use a form, give the form name of the database field that you want to compare, and the value of the form input is the value you want to search for example 3, or some name. Then when the value returned is null, you normally don't take the field into the sql string. Its just some formatting you have to use in the controller, and its all automated, if the main purpose is directory listing or similar stuff

Thread Thread
 
mohammadfouladgar profile image
Fouladgar.dev

I suggest using the package once.
The query goes to the database only once.