dimanche 3 avril 2016

Laravel relationship to show all posts by authors that they follow

Can normally figure these relationships out but stumped on this one.

I have a basic blog platform that allows user to sign up and post blog posts.

Users can also follow other users.

I am trying to make a view where I can see all of the blog posts by the authors that I follow

I have the normal users table, and then a blog posts table which contains the user_id of the creator.

For followers, I then have a pivot table called followers which has user_id and follower_id.

This is my basic line to get all posts:

$posts = Post::orderBy('created_at', 'DESC')->get();

How can I change that so it only shows the posts where there post user_id is a field that matches in the followers table?

Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire