這裏是我的表結構:如何獲得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
那麼你的問題是什麼? –