Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

Please help me to convert the following query to Laravel Eloquent. I am struggling to covert sub-query and if statements.

SELECT *
FROM (
SELECT
        IF (msg.from_id = '2', msg.from_id, msg.to_id) AS my_mail,
        IF (msg.to_id = '2', msg.from_id, msg.to_id) AS their_mail,
        IF (msg.to_id = '2', msg.recipient_deleted_at, msg.sender_deleted_at) AS deleted_at,
        msg.*
    FROM msg
    WHERE (msg.from_id = '2' OR msg.to_id = '2')
    HAVING deleted_at IS NULL
    ORDER BY created_at DESC
) msg
GROUP BY msg.my_mail, msg.their_mail
ORDER BY msg.created_at DESC
share|improve this question

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.