-
Notifications
You must be signed in to change notification settings - Fork 11.1k
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
[8.x] Add where helpers for boolean and where not #38437
Conversation
Dumb question, will it work with any "evaluates as true" value? i.e. true, 1, "true" etc |
Hit enter too soon. I love it, regardless of the answer! |
@mrpritchett that may depend on the database system? I know on MySQL I can do |
How would it work in cases like this? I'd expect the result to be the same as: |
@pablius - it doesn't work that way. Again, this is just for boolean comparisons. We already have a |
Looking at the code it would just translate into For your scenario there is always |
I think its a great addition, my only concern is whether it should be User::whereNot('points', '>', 10)->get();
// Equivalent...
User::where('points', '<=', 10)->get(); or something along these lines. I don't feel super strongly about this but thought it was worth consideration. Also a little curious if Would a non-string column work: ->whereNot([['foo', 1], ['bar', 2]]); |
Think it's a little too much. There's a lot of "where" helpers already and the more you have, the less intuitive they tend to be.
But like all helpers, I never want them but always use them once they're merged so.... 🤷🏻♂️
|
If we want to be super explicit we could have |
Thanks for your pull request to Laravel! Unfortunately, I'm going to delay merging this code for lol jk. Seems fine to me, because they're lexically correct. Usually these can be chained against boolean columns, which by convention start with User::query()->where('is_admin')->first(); The thing is, should be this equivalent to adding the column name to a where clause? User::query()->whereIsAdmin()->first(); |
That would be more descriptive. These kinds of helpers become really confusing at scale projects (1k+ ✌🏼 |
I love the concept, but I'm not completely sold on the implementation. Problem 1: Problem 2: These would both be fixed by instead of using the A lot of programmers have some (or a lot of) knowledge of SQL, and seeing a |
Love it, in my opinion these methods are more clean |
Love this too, I always go to type whereTrue or whereFalse and realise it doesn't exist! A great addition. |
This could be a great addition! also a better understanding method for all! |
@sebastiaanluca IMO that is just reading too much into the method. It is simply a shortcut that allows you to not have to specify the |
I'm flattered by the mention, but you got the wrong Sebastiaan 😄 @sebastianvitterso |
Too much confusion over this. |
IMHO whereNot and orWhereNot should be in the framework, cuz every other where has a not variant, on top of that it's a valid sql syntax |
I realize you closed the issue, but I believe @shadoWalker89 has a good solution, and that his PR should be reconsidered.
I disagree. When you write I acknowledge that with the implementation in this PR, the |
Oh, sad! I didn't realize this wasn't merged and just now saw all the discussion around it. Shame, but I get it. :)
I think this was my initial suggestion so I'd have dug this. I do like keeping things super explicit, especially if it turns out to be too confusing. If you'd consider a more explicit implementation, I may be up for trying to reproduce it myself sometime. |
This PR adds a few small convenience methods to the query builder courtesy of inspiration by @simensen...
First, passing only a column name to the query builder will now add a where clause ensuring that the value of the column is
true
:In addition,
whereNot
andorWhereNot
methods have been added. Typically, this generate traditional<>
clauses:In addition, passing only a column name to this method will add a "where false" clause to the query:
Let me know what you think!