2017-04-17 52 views
0

我嘗試我的查詢轉換爲laravel查詢生成器,但我不能獲得成功,我的查詢是mysql如下:如何MySQL查詢轉換爲laravel的QueryBuilder

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查詢建設者或laravel雄辯?

回答

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(); 
+0

謝謝您的回答,但它給了我錯誤'方法getBindings不exist' – HirenMangukiya

+0

嗨,我已經更新了代碼,請你再檢查一次! – linktoahref