Vote count:
0
I what to display a feed page for a authenticated user which shows the latest posts from users that they follow. I have a follow system set up already which has the following:
Tabels:
User model:
public function follow() {
return $this->BelongsToMany( 'User', 'Follow' ,'follow_user', 'user_id');
}
Feed controller:
public function feed () {
$user = (Auth::user());
return View::make('profile.feed')->with('user',$user);
}
Feed.blade
@foreach ($user->follow as $follow)
@foreach ($follow->posts as $post)
//* post data here.
@endforeach
@endforeach
This is pulling in the posts from the users a user follows but, i have a problem. The foreach is returning a user and then their posts each time.
What its doing now:
Followed user 1
- Post 1
- Post 2
- Post 3 etc etc
Followed user 2
- Post 1
- Post 2
- Post 3 etc etc
What i would like to display:
- Followed User 1 Post 1
- Followed User 2 Post 1
- Followed User 2 Post 2
- Followed User 1 Post 2 etc etc
Any ideas?
asked 24 secs ago
Get posts by followers laravel
Aucun commentaire:
Enregistrer un commentaire