Replies: 1 comment 2 replies
-
Both existsOr($closure) and doesntExistOr($closure) are useful for their ability to return value from the callback, so you can put extra check inside callback:
Yes, we can get the same result with a:
But what about that "readability"? Why void? Wouldn't it be better to return some CheckExistenceResult object, to chain actions:
So removing the need for - if (...->exists()) {...} else {...}? I can't say, what would be better: to bloat api or to make BC. How often people use existsOr? |
Beta Was this translation helpful? Give feedback.
2 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I was about to create an update to have new methods on the Query\Builder class, whenExists($closure) and whenDoesntExist($closure), the premise is simple, run a closure when the exists test is true. The main reason I want to do this is code readability. e.g.
At this point I noticed existsOr($closure) and doesntExistOr($closure), which is effectively the same, except it has a mixed return value. I feel like the naming of whenExists() is more readable, it's closer to natural language and it's better targeted at the focal point, the closure, the existing name reads like it's inverse, i.e. to run the closure when records exists use doesntExistOr method.
So, my questions to the community are these, is it worth a pull request to rename this method and change return value to void? Or, if the existing context is worthwhile keeping, is it worth creating totally new methods specific to this purpose with the different naming and void return?
Ps. clean and succinct code is the goal, so removing the need for - if (...->exists()) {...} and helping readability.
Beta Was this translation helpful? Give feedback.
All reactions