Adding Model::whereEmpty('column')
and Model::whereNotEmpty('column')
to the query builder
#47985
Unanswered
kylemilloy
asked this question in
Ideas
Replies: 1 comment 1 reply
-
To be honest would make sense, but isn't more safe to review the place where field is updated and force null in case is an empty string? |
Beta Was this translation helpful? Give feedback.
1 reply
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.
Uh oh!
There was an error while loading. Please reload this page.
-
I have an eloquent model where sometimes the value is
NULL
and sometimes it's an empty string and with the DB I'm using I need to use the following to get both values:What I think might be a nice helper function is where we check for
whereEmpty('column')
instead. My idea here is that this follows PHP'sempty($var)
method and behind the scenes would evaluate similarly.I'm not wild about including JSON/arrays into this as that might have other side effects (like shouldn't {} also be empty?) but am looking to bounce some ideas off people and can add this.
Similar discussion here but looks like it never got traction.
Edit
Might also be good to include
orWhereEmpty
andorWhereNotEmpty
? But maybe that's a yagni situation.Beta Was this translation helpful? Give feedback.
All reactions