-
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
DB::raw() in whereDate() is also applied to following where clauses #22213
Comments
does it occur in 5.5? |
I have tested it on 5.5.21 and it still occurs.
generates the next query string:
|
If you do it like this:
Does it throws an error or works exactly like you expected? |
With that code it works:
So the problem seems to be only with the method DB::raw in whereDate, as @dattz pointed. |
It looks like the value is bound twice, as any subsequent where clause bindings will be shifted over, rather than replaced:
results in:
As a workaround, consume the extra bound value in a way that won't alter your query, such as:
which results in something like:
|
Honestly i wouldn't use
|
@srmklive Slight correction, you forgot to add the date part of the query ( I guess turning the whereDate into a whereRaw is probably a more sensible workaround than consuming the extra binding. In any case, this is still a bug in the framework that should be fixed. |
Hmm I'm doing this query : and my sql script looks like this : "select * from |
I would suggest you using the Carbon library to get the current date. |
executing : Orders::whereDate('ordered_on', '>', \DB::raw('CURDATE()'))->where('status', 'Complete')->get(); generates the following input in the querylog: array:1 [▼ Is this kinda what you we're looking for ? |
If the bug is not already fixed, I would like to try and solve it, could anyone confirm that this issue is still open ? |
Well using the whereDate seems to be the issue, cause when using a where clause like this: Orders::where('ordered_on', '<', \DB::raw('CURDATE()'))->where('status', 'Complete')->get(); dd(DB::connection()->getQueryLog()); -> array:1 [▼ seems to work fine. |
Description:
If
DB::raw()
is used inwhereDate()
, the followingwhere
clauses also get the same value supplied toDB::raw()
.Steps To Reproduce:
DB::raw()
inwhereDate()
and uses anotherwhere
clause followed by it (The order matters. First use the,whereDate()
, then use the otherwhere
method). Example:Orders::whereDate('ordered_on', '>', \DB::raw('CURDATE()')->where('status', 'Complete');
select * from 'orders' where date('ordered_on') >= CURDATE() and 'status' = 'CURDATE()'
Notice the
'status' = 'CURDATE()'
.The text was updated successfully, but these errors were encountered: