laravel 打印sql语句

时间:2022-05-19 08:32:51
public function getCurrencyOrder($user_id=70,$pid=252,$register=['register:first'])
{
DB::connection()->enableQueryLog(); // 开启查询日志
$data=CurrencyOrder::selectRaw("sum(amount) AS total")
->where('owner_id',$user_id)
->where('target_id',$pid)
->where('type',1)
->whereIn('target_type',$register)
->value('total');
// dd(DB::table('question')); // 要查看的sql
$queries = DB::getQueryLog(); // 获取查询日志
dd($queries);
if(!$data){
$data=0;
} return $data; }
打印结果:
laravel 打印sql语句