这里是我的表结构:如何获得laravel的最后一篇文章?
// posts
+----+--------------+---------+
| id | post_content | user_id |
+----+--------------+---------+
| 1 | content1 | 65743 |
| 2 | content2 | 24711 |
| 3 | content3 | 45541 | -- this
| 4 | content4 | 55743 |
| 5 | content5 | 95441 |
| 6 | content6 | 45541 | -- this
| 7 | content7 | 24711 |
| 8 | content8 | 45541 | -- this (I want to select this one, Because it is the last one)
| 9 | content9 | 24711 |
+----+--------------+---------+
正如我上面已经评论说,我想下面一行,假设$user_id = 45541
| 8 | content8 | 45541 |
我如何能做到这一点的Laravel?
我试过到目前为止:
$last_post = Posts::where('id', $user_id)->OrderBy('id', 'desc')->first();
什么不适合你的尝试? –
@u_mulder emm我不知道,我还没有测试。 – stack
那么你的问题是什么? –