6 months ago

Getting strange things when using where() with join() - adds = '' at the end of join

Posted 6 months ago by MartinZeltin

I am getting this strange query from my join subquery (notice the = '' at the end)

inner join
as `joined` on `date(joined`.`created_at) = date(cash_register_order_total_history`.`created_at)` = '' order by date_of_month

Why does Laravel add the strange = '' at the end? I'm getting a syntax error because of it.

Here is my query

$join2 = \App\Models\CashRegisterOrderTotalHistory::from('cash_register_order_total_history as history')
        ->select('order_sum as last_order_sum', 'created_at')
        ->where('created_at', function($query) {
            $query->selectRaw('max(created_at) from cash_register_order_total_history history2 where date(history2.created_at) = date(history.created_at)');

$results = \App\Models\CashRegisterOrderTotalHistory::selectRaw('
    date(cash_register_order_total_history.created_at) as date_of_month,
    weekday(cash_register_order_total_history.created_at) + 1 as day_of_week,
    sum(order_sum) as total_order_sum,
    sum(items.total_beef_used) as total_beef_used,
    max(cash_register_order_total_history.created_at) as lastorderdate,
    max(joined.last_order_sum) as last_order_sum
')->joinSub($join2, 'joined', function ($join) {
   $join->on('date(joined.created_at) = date(cash_register_order_total_history.created_at)');

Please sign in or create an account to participate in this conversation.