Skip to content

[10.x] Added whereTrue() and whereFalse() method to query builder #46307

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed

Conversation

troccoli
Copy link
Contributor

@troccoli troccoli commented Mar 1, 2023

This PR is in response to a pool I took: #46071 .

It's not uncommon to have boolean fields in tables, and querying for them is only possible with something like

$query->where('admin', true);

To make the code more readable, this PR adds two methods: whereTrue() and whereFalse(), plus the "or" versions. So now, the query above can be rewritten as

$query->whereTrue('admin');

The SQL created is

"admin" = true

which is valid in MySQL, PostgreSQL, SQLite and SQL Server

@troccoli troccoli force-pushed the add-support-for-query-builder-whereis branch from aa13ffa to 533a7fb Compare March 1, 2023 11:41
@troccoli troccoli marked this pull request as draft March 1, 2023 11:45
@milwad-dev
Copy link
Contributor

#43088

@troccoli troccoli changed the title Added whereTrue() and whereFalse() method to query builder [10.x] Added whereTrue() and whereFalse() method to query builder Mar 2, 2023
@troccoli troccoli force-pushed the add-support-for-query-builder-whereis branch 4 times, most recently from 467d1b6 to dbc93d6 Compare March 2, 2023 09:48
@troccoli troccoli force-pushed the add-support-for-query-builder-whereis branch from dbc93d6 to 46335cc Compare March 2, 2023 09:58
@troccoli troccoli marked this pull request as ready for review March 2, 2023 10:03
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

@troccoli troccoli deleted the add-support-for-query-builder-whereis branch April 7, 2023 07:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants