0
나는 쿼리에 몇 가지 문제가있다. 테이블에서 각 '카테고리'에 대한 최신 레코드를 가져 오려고하지만 Laravel에 쿼리를 작성하는 방법을 알 수 없습니다.MySQL to Eloquent query
나는 MySQL에서 작동하는 쿼리를 얻었지만, 실제로 번역 할 필요는 없다.
MySQL의 쿼리는 다음과 같습니다
SELECT *
FROM messages
WHERE id IN (
SELECT MAX(id)
FROM messages
GROUP BY conversation_id
);
내가 Laravel에서이 같은 시도했지만 작동하지 않는 것 :
return self::where(function($query){
$query->select(max(['id']))
->from('messages')
->groupBy('conversation_id');
})
->get();
가능한 중복의 : http://stackoverflow.com/questions/16815551/how-to-do-this-in-laravel-subquery-where-in 최종 쿼리는 어떤 관심 들어, 다음과 같습니다 http://stackoverflow.com/questions/27064678/how-to-create-a-subquery-using-laravel-eloquent – AlexM