0

I try to convert my query to laravel query builder but i cant get succeed, my query is in mysql as below:

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

So how do i convert it into laravel query-builder or laravel eloquent?

1 Answer 1

1

Have you tried

$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();
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your answer but it gives me error Method getBindings does not exist
Hi, I've updated the code, could you please check again!

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.