@kaju74 ModelName::latest('column_name')->get();
May 4, 2016
7
Level 5
Get latest records ordered by date?
Hi, I've a problem getting the latest records of a tables ordered by another column.
So, here are some demo records:
"user_id";"start_at";"end_at";"target";"actual";"delta";"balance";"data";"created_at"
"113";"2016-05-02 00:00:00";"2016-05-08 23:59:59";"39,5";"39,5";"0";"0";"data";"2016-05-04 12:25:11"
"113";"2016-05-02 00:00:00";"2016-05-08 23:59:59";"39,5";"39,5";"0";"0";"data";"2016-05-04 12:23:32"
"113";"2016-05-09 00:00:00";"2016-05-15 23:59:59";"39,5";"39,5";"0";"0";"data";"2016-05-09 12:58:01"
"113";"2016-05-09 00:00:00";"2016-05-15 23:59:59";"39,5";"39,5";"0";"0";"data";"2016-05-04 12:25:11"
"113";"2016-05-09 00:00:00";"2016-05-15 23:59:59";"39,5";"39,5";"0";"0";"data";2016-05-04 12:23:32"
I want to get only the latest created records (created_at) from every available week (start_at). As you can see, there are two records for the week from 2016-05-02 and three records for 2016-05-09. The final result should be:
"user_id";"start_at";"end_at";"target";"actual";"delta";"balance";"data";"created_at"
"113";"2016-05-02 00:00:00";"2016-05-08 23:59:59";"39,5";"39,5";"0";"0";"data";"2016-05-04 12:25:11"
"113";"2016-05-09 00:00:00";"2016-05-15 23:59:59";"39,5";"39,5";"0";"0";"data";"2016-05-09 12:58:01"
How do I write the eloquent query for this? I've tryed several things, but nothing works 8-(
Thank you very much, Marc
P.S.: I know, one 'created_at' date is in the future ;-)
Please or to participate in this conversation.