0

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?

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks Mohammad, its exactly that weirdly, I was debugging for other errors on my SQL statement and happened to see that when output to SQL
1

If you want to see the full output with your parameters in place, you can do the following:

use Illuminate\Support\Str;

$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)'));
    
dd(Str::replaceArray('?', $transactions->getBindings(), $transactions->toSql()));

That will replace the ? characters with their actual binding values from your query.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.