AR查询,怎么获取这个查询的Sql语句
public function getProductInfo()
{
//leftJoin 联表查询 leftJoin('tableA','tableA.column','condition','tableB.column');
$productInfo = DB::table('product')
->leftJoin('product_tag','product.id','=','product_tag.product_id')
->leftJoin('tag','product_tag.tag_id','=','tag.id')
->select('product.category as category','product_tag.product_id as product_id','product_tag.tag_id as tag_id','tag.name as tagName','tag.source as source')
->get();
return $productInfo;
}
怎么打印或者获取到最新执行的SQL语句
3 个回复
zhuowenji - 卓文吉吉吉吉吉吉
赞同来自: Mr_Jing 、FiveSay
$a = end($queries);
$tmp = str_replace('?', '"'.'%s'.'"', $a["query"]);
echo vsprintf($tmp, $a['bindings']);
exit;
雨师
赞同来自:
装https://github.com/barryvdh/laravel-debugbar就可以了
不过真的带的页面很慢。。。开发环境也没所谓啦
俭以养德
赞同来自:
tosql()函数,能获取最新一次执行的SQL语句
DB::table($thi->table)->tosql()