Please how can I rewrite this in Laravel eloquent

  eloquent, laravel

"select users.id, users.name, users.avatar, users.email, messages.message, messages.is_read,
messages.msg_to, messages.msg_from, messages.created_at, max(messages.created_at) as max_created_at
from users LEFT JOIN messages ON users.id = messages.msg_from and is_read = 0 and messages.msg_to = " . Auth::id() . "
where users.id != " . Auth::id() . " AND users.id IN
( SELECT friends.friend_id from friends WHERE friends.user_id = " . Auth::id() . " AND friends.accept = 1 ) OR users.id IN
( SELECT friends.user_id from friends WHERE friends.friend_id = " . Auth::id() . " AND friends.accept =1 )
group by messages.created_at, users.id, users.name, users.avatar, users.email, messages.message, messages.is_read,
messages.msg_to, messages.msg_from ORDER BY max_created_at DESC"

Source: Laravel

Leave a Reply