jeudi 1 septembre 2016

Displaying posts of users the user follows through Laravel relationships

I would like to display the posts of everyone the current user follows, ordered by date desc.

I have a many to many relationship supplying all the people the user is following.

$users = User::find(Auth::user()->id)->follow()->get();

I have a one to many relationship displaying the posts for any user.

$updates = App\User::find(?????)->updates()->orderBy('created_at', 'desc')->get();

The question mark's shows where the followers ID's need to be placed.

I can put the above query inside the for each loop but that obviously works its way through each follower rather than all posts in date order.

I suspect I may need to set a new relationship and work from the beginning. Can anyone advise.

Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire