Search code examples
laraveleloquentquery-builderlaravel-query-builder

Laravel query builder not returning the correct sql statement, the strings look like variables


I have the following Laravel query, it does not appear to be returning the $abort and $pend variables as strings:

$abort = "Aborted";
$pend = "Pending";
$transactions = DB::table('callpay_transactions')
->select(DB::raw('SUBSTR(created,1,7) as YrMth') ,DB::raw('SUM(amount) as total_sales'  ))
->where('status', '!=', $abort)
->where('status', '!=', $pend)
->groupBy(DB::raw('SUBSTR(created,1,7)'))
    ->toSql();
    
dd($transactions);

The return sql query is as follows

"select SUBSTR(created,1,7) as YrMth, SUM(amount) as total_sales from `callpay_transactions` where `status` != ? and `status` != ? group by SUBSTR(created,1,7)"
        

Any ideas as to why my $abort and $pend variables show as strings?


Solution

  • i thing that is because of prepared statment and ? also indicate a placeholder while using prepared statment in php. instead of to sql if you us get you will see the result.