abbasudo / laravel-purity

An elegant way to filter and sort queries in Laravel
https://abbasudo.github.io/laravel-purity/?utm_source=github&utm_medium=about
MIT License
474 stars 44 forks source link

Can't Filters Numeric Values And Boolean Values #68

Open AhnabShahin opened 6 months ago

AhnabShahin commented 6 months ago

Filter example :

Database Using : MongoDB using https://github.com/mongodb/laravel-mongodb

Problem Details:

The URL parameters are being converted into strings, but the corresponding values in my database are integers or floats. As a result, there's a mismatch and I'm not getting any matching results.

image

AhnabShahin commented 6 months ago

Thank you to the author and contributors for creating this useful package! Purity has significantly enhanced my workflow, and I deeply appreciate the effort and dedication that has gone into its development.

However, I have encountered an issue where I can't filter numeric values and Boolean values. Here is the solution in a pull request that will convert the value into a numeric if it is numeric, or a Boolean if it is Boolean

PR For Issues 68

abbasudo commented 6 months ago

Hi @AhnabShahin . It's good to hear that Purity helped you in your projects. Also, Thank you for your contribution to Purity. In Purity, values get converted to a string and won't cause any errors because Purity in its core uses Laravels query builder, for example, the $eq uses the where() function from eloquent. This function accepts string values and converts them into corresponding values. in the case of boolean values, you must filter them by 0 and 1. Furthermore, in #70 I added more tests for different value types to confirm the correctness of Laravel Purity. Check out this tests

abbasudo commented 6 months ago

@AhnabShahin keep in mind all of our tests are running in SQLite and MySQL databases and Eloquent if you have any errors it is related to MongoDB and Moloquent. Do have mismatched results?

AhnabShahin commented 5 months ago

@abbasudo It's not an error! I'm just getting mismatched results when using MongoDB with the help of the "laravel-mongodb" package, which is the official MongoDB package for Laravel. If this "Purity" package doesn't support MongoDB, I'm willing to fork it to make it workable and suitable for myself.

abbasudo commented 5 months ago

@AhnabShahin that's great. Please inform me of any updates on your fork.