0
SELECT *, (
    SELECT count(id) FROM order_history oh 
    WHERE oh.refund_of = oh1.id
) "refunds"
FROM order_history oh1 
WHERE `object_name` 
NOT LIKE '%refund%'

I need to translate this into eloquent hopefully without using Db::raw

1
  • Add your database structure Commented Apr 13, 2016 at 7:17

1 Answer 1

1

You should be able to add a sub select query with the method select() or addSelect() as shown here.

Example:

select(DB::raw(count(id) FROM order_history oh WHERE oh.refund_of = oh1.id))

Note: "These expressions will be injected into the query as strings, so be careful not to create any SQL injection points!"

Sign up to request clarification or add additional context in comments.

Comments

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.