Obter a linha mais recente com o grupo by e o Laravel
Embora existam várias perguntas como essa, não consigo que minha consulta retorne a linha com a data mais recente com um grupo por.
Eu tenho a seguinte tabela ..
| message_id | from | to | created_at | status
----------------------------------------------
| 1 | 1 | 2 | 2017-04-06 | 1
| 2 | 1 | 2 | 2017-04-07 | 0
| 3 | 3 | 4 | 2017-04-06 | 1
| 4 | 3 | 4 | 2017-04-07 | 0
----------------------------------------------
e estou tentando obter as linhas com a data mais recente.
| message_id | from | to | created_at | status
----------------------------------------------
| 2 | 1 | 2 | 2017-04-07 | 0
| 4 | 3 | 4 | 2017-04-07 | 0
Atualmente, essa consulta retorna as linhas com a última data recente.
$messages = Message::where('to', Auth::id())
->groupBy('from')
->orderBy('created_at', 'DESC')
->paginate(10);