-
Notifications
You must be signed in to change notification settings - Fork 11.2k
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
Add relative date shorthands to Query Builder #54408
base: 11.x
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can't say, I like the naming, though. I'd prefer something like whereDateBefore
and whereDateAfter
or the like 🤔
It would be nice if there was a trait class for date relations like |
I am shocked that there is any resistance to this at all. The changes are small, solve a common paper cut, and don't impose any obvious performance penalties. I am definitely all for this. |
@selcukcukur There could be a trait for all
@nexxai It adds yet another |
For PostgreSQL this would have to use a full iso-8601 date with timezone. |
@tpetry, do you know if the underlying Follow-up: A quick dump shows that |
Yeah, its not correct currently for PG. I think the best approach would be copying the implementation of if ($value instanceof DateTimeInterface) {
$bindings[$key] = $value->format($grammar->getDateFormat());
} |
@tpetry, my humble vote would be to merge this and then address that in a separate PR for |
I PR'd a version of this almost 3 years ago and still reach for it. So I figured I'd give it another shot.
This adds a few relative, human readable shorthands for working with dates (cause dates are hard).
While I appreciate this adds weight to this ever growing class, there are dozens of other shorthands. Queries are something devs write everyday. As such, I believe any shorthand continues to improve the DX of Laravel.
All of these methods have their
where
,or
, andorWhereNot
counterparts. All methods also accept an array of column names as the first argument. ThewherePast
andwhereFuture
have an optional second argument to set$now
.