Level 5
@ardf16 Try
Post::select(DB::raw("DATE_FORMAT(updated_at, \"%m-%Y\") AS updated_month"))
->groupBy('updated_month')
>orderBy('updated_month', 'DESC')
>get();
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, i have this query:
Post::select(DB::raw("DATE_FORMAT(updated_at, \"%m-%Y\") AS updated_month"))
->groupBy('updated_month')
>orderBy(DB::raw("STR_TO_DATE(updated_month, \"%m-%Y\")"), 'DESC')
>get();
wchich outputs query:
select DATE_FORMAT(updated_at, "%m-%Y") AS updated_month from `posts` group by `updated_month` order by STR_TO_DATE(updated_month, "%m-%Y") desc
Eloquent returns collection unsorted... The same exact query in heidisql returns dates properly sorted.
what's going on here?
Please or to participate in this conversation.