Skip to content
Advertisement

Laravel and Eloquent – applying different filters

I’m feeling stuck. 🙁

I want to be able to execute different SQL query, depending on the selected filters in my form:

I have a class called “Interaction” which extends the Eloquent model and I need to be able to execute the above query or represent the same logic through it.

Any ideas on how I can achieve that will be greatly appreciated!

EDIT: Thanks to Brice (my personal hero today), here is what did the trick for me:

Advertisement

Answer

I’d recommend using the eloquent query builder for this.

For example:

If you have a lot of results, you may want to use pagination instead of fetching all results at the same time as shown above.

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement