我将数据存储在我的数据库中。存储的数据如下所示
id | upload_month | created_at
-----------------------------------------
1 | January | 2017-01-30 13:22:39
-----------------------------------------
2 | Febuary | 2017-01-30 13:23:42
-----------------------------------------
3 | January | 2017-01-30 13:25:33
在我的控制器中,我试图检索不同的 upload_month,但获取每个最新插入的版本。目前我正在尝试
$uploadedFile = UploadedFile::groupBy('upload_month')->orderBy('created_at', 'desc')->get();
问题是这将返回以下内容
id | upload_month | created_at
-----------------------------------------
1 | January | 2017-01-30 13:22:39
-----------------------------------------
2 | Febuary | 2017-01-30 13:23:42
-----------------------------------------
因此,对于一月份的记录,它提供的是旧版本。如果我将其更改为->orderBy('created_at', 'asc')
它返回相同的记录,但二月是第一行。
从本质上讲,我追求的是这个
id | upload_month | created_at
-----------------------------------------
1 | January | 2017-01-30 13:25:33
-----------------------------------------
2 | Febuary | 2017-01-30 13:23:42
-----------------------------------------
我怎样才能做到这一点?
谢谢