php - Get latest values in GROUP BY using Laravel Eloquent ORM -


i'm trying understand how laravel's eloquent orm works , looking @ following mysql query:

select id, name, date tablename group name order date 

the use of group by returns oldest values of name. there way return latest value instead?

try following code,

tablename::select('id', 'name', db::raw('max(date) latest_date'))  ->groupby('name')  ->orderby('latest_date')  ->get() 

Comments

Popular posts from this blog

matlab - How to equate a structure array to structure array -

c# - Operator '==' incompatible with operand types 'Guid' and 'Guid' using DynamicExpression.ParseLambda<T, bool> -