Replies: 1 comment
-
Thanks for the link to the package. I'm very surprised that this is not in Laravel, as it seems like basic functionality to me. I searched in the PRs and it seems this feature was proposed several times, but was always rejected. Here's the latest attempt with a long discussion: #38437 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I'm not quite sure if this particular package may already offer a solution for this (although I've given it a quick test and it seems to mainly apply to actual Eloquent Models rather than to the base Query Builder option, which is more of what I'm using for this particular project since my tables don't follow all of the typical Laravel conventions...this particular table down below utilizes a composite primary key for example):
https://github.com/protonemedia/laravel-eloquent-where-not
But from what I can see, it does not appear that this particular option is currently available in Laravel, so I'm submitting it as a feature idea since I think it can be useful to have available if the need comes up.
The existing
where()
method works fine for basic simple where conditions and there are some other methods already available that start withwhereNot...()
but there does not appear to be an actualwhereNot()
method already available (unless I've overlooked it).I don't think this situation comes up very commonly, but I think it would be helpful to have an option for this available at the framework level, since otherwise it means reverting to using
whereRaw()
or adjusting the logic in a more complex manner (example below).Basically, I already have an existing query that looks like the following:
And it would be generated by some query builder code that looks like this for example:
And the need has come up where I want to retrieve the opposite population for the query above so I was thinking about the simplest way to do that query-wise and it would be to simply add a NOT operator in front of that condition like this:
But since there is no
whereNot()
method available, I can't write something like this since it won't work as expected:My main alternative is to rewrite the logic within the nested where closure like this (which can sometimes be a little tricky to get right and also requires extra changes, such as making sure I change the
orWhere()
usage towhere()
instead in addition to changing the=
usage to!=
):Beta Was this translation helpful? Give feedback.
All reactions