Skip to content

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 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 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.

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