Performing A Groupwise Maximum In Laravel 4
What's the best way to perform a groupwise maximum using Laravel's Eloquent ORM such that it returns instances of models?
Solution 1:
Based on this stackoverflow answer, I was able to create the following:
$query = MyModel
::from(DB::raw(
'my_models NATURAL JOIN (
SELECT user_id, MAX(created_at) created_at
FROM my_models
GROUP BY user_id
) t'
))
;
Post a Comment for "Performing A Groupwise Maximum In Laravel 4"