【发布时间】:2018-07-19 00:44:40
【问题描述】:
我有一张桌子posts 和posts_contents。
而且我只想从一个帖子中获取内容,前提是该帖子具有display = 1。
(由于语言支持,我需要两个单独的表格)
帖子:
id user_id display
1 2 0
2 2 1
3 2 0
4 2 1
posts_contents
id post_id lang_id name description
1 1 1 Hello World
2 2 1 Here Is What I wanna show!
3 3 1 Don't Show the others
4 4 1 Hey Display that one too
所以在 laravel 中我使用了雄辩的关系,但我只是不明白如何在这种特殊情况下使用它。在文档中,我发现只有以下情况:
$p = App\Posts::find(1)->contents;
效果很好,但是我想要的是这样的:
$p = App\Posts::where('display',1)->contents;
但它不起作用......所以问题是:这样做的正确方法是什么?
感谢任何帮助,谢谢!
更新
我需要同时获得多个帖子,而不仅仅是一个。
【问题讨论】:
-
@ka_lin 是可选的