如何将mysql查询转换为laravel querybuilder

时间:2017-04-17 06:34:34

标签: laravel laravel-5 laravel-query-builder

我尝试将查询转换为laravel查询构建器,但我无法成功,我的查询位于mysql,如下所示:

SELECT p.seller, p.purchase_date, p.report_no FROM purchases AS p UNION SELECT ps.seller, ps.purchase_date, ps.report_no FROM purchase_solds AS ps ORDER BY purchase_date DESC

那么我如何将其转换为laravel query-builder或laravel eloquent?

1 个答案:

答案 0 :(得分:1)

你试过吗

$purchases = DB::table('purchases')
                 ->select('seller', 'purchase_date', 'report_no');

$purchase_solds = DB::table('purchase_solds')
                      ->select('seller', 'purchase_date', 'report_no')
                      ->union($purchases)
                      ->orderBy('purchase_date', 'desc')
                      ->get();