我需要在集合中返回以进行分页,但我只能在数组中返回,因为查询使用自然 JOIN。我如何使用 Laravel 集合进行此查询:
SELECT mensagens.* FROM mensagens NATURAL JOIN (SELECT id_emissor, MAX(created_at) created_at FROM mensagens WHERE id_receptor = ".$user_id." GROUP BY id_emissor) t
我用过这段代码:
$mensagem = \DB::select(DB::raw("SELECT mensagens.* FROM mensagens NATURAL JOIN (SELECT id_emissor, MAX(created_at) created_at FROM mensagens WHERE id_receptor = ".$user_id." GROUP BY id_emissor) t") );