Reputation: 1798
I have a piece of my code I need to change from this
->rightJoin('calendar', function($join) use ($machineName)
{
$join->on('print_jobs.job_date', '=', 'calendar.datefield')
->where('machines.machine', '=', $machineName);
})
To
->rightJoin('calendar', function($join) use ($machineName)
{
$join->on('DATE(print_jobs.job_date)', '=', 'calendar.datefield')
->where('machines.machine', '=', $machineName);
})
Notice I am changing the print_jobs.job_date from datetime to date. This worked fine until i changed the field from date to a datetime.
Eloquent does not like me adding DATE here. I dont know how to just put the raw join field here.
Upvotes: 1
Views: 1150
Reputation: 50798
This is not Eloquent, this is the fluent query builder, to be clear. Next, the issue is that it doesn't know how to handle DATE()
because it only expects a string, not a method. To work around this, use theraw()
method off of the DB facade. I've included the full namespace below, but you can just use
it at the top of the file and reference DB::raw()
for brevity.
$join->on(Illuminate\Support\Facades\DB::raw('DATE(print_jobs.job_date)'), '=', 'calendar.datefield')
Upvotes: 1