spatie / laravel-query-builder

Easily build Eloquent queries from API requests
https://spatie.be/docs/laravel-query-builder
MIT License
4k stars 392 forks source link

[FEAT] add filter by operator #940

Open AbdelrahmanBl opened 3 months ago

AbdelrahmanBl commented 3 months ago

Dear sir I had been developed out of the box a method for filtering by operator. for the example:

QueryBuilder::for(User::class)
->allowedFilters([
    AllowedFilter::operator('salary', FilterOperator::GREATER_THAN),
])
->get();

Note: I realized that there is some old test cases not working.

siarheipashkevich commented 3 months ago

@AbdelrahmanBl is it possible to pass the operator through query parameters?

AbdelrahmanBl commented 3 months ago

It's really a great idea! Now you can search by a dynamic filter operator. for the example:

// users?filter[salary]=>=1000,<=3000
QueryBuilder::for(User::class)
->allowedFilters([
    AllowedFilter::operator('salary', FilterOperator::DYNAMIC),
])
->get();
AbdelrahmanBl commented 3 months ago

@freekmurze

AbdelrahmanBl commented 2 months ago

Hello sir! How are you? Can you check this feature? @freekmurze

benswinburne commented 2 months ago

Hello sir! How are you? Can you check this feature? @freekmurze

@AbdelrahmanBl Please stop deleting your previous comment and @ people. No doubt they're busy and they'll get to it when they get to it.

AbdelrahmanBl commented 2 months ago

Thank you for your response 🙏 and i won't contribute with spatie anymore for not annoying them.

benswinburne commented 2 months ago

I'm not from Spatie, just someone whose inbox you were spamming. Repeatedly @ing anyone isn't productive be it Spatie or anyone else.

I'd subscribed to the thread because i'm interested in the feature as I'm sure others are too. Closing it because someone suggest you be patient seems overkill, but it is your PR to do what you will with.

AbdelrahmanBl commented 2 months ago

I thought you were from spatie and no problem i will reopen it to benefit the others 😊

AbdelrahmanBl commented 1 month ago

@freekmurze kindly check this commit!