I have a table posts
and posts_contents
.
And I want to get a content from one post only if that post has display = 1
.
(I need two separate tables because of language support)
posts:
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
So in laravel I use eloquent relationships, but I just don't understand how to use it in that particular case. In the documentation I found only cases such as:
$p = App\Posts::find(1)->contents;
Which works great, however what I want is something like this:
$p = App\Posts::where('display',1)->contents;
But it doesn't work... So question is: what is the right way to do so?
Any help is appreciated, Thanks!
Update
I need to get multiple posts at once, not just one.