Having these 3 tables:
users
- user_id
- first_name
- last_name
- etc.
posts
- post_id
- title
- body
- etc.
posts_users
- post_id
- user_id
The post - user relation means that a user is following a post.
The simplest way of listing posts would be:
$posts= Posts::all();
foreach ($posts as $post)
{
var_dump($post->title);
}
But when listing posts I would love to also query if the current user (say user_id = 5) is following each post.
So for each post I would have post_id, title, ..., is_following [0 or 1].
I can do this using simple SQL, but can this be done the Eloquent way?