Fetch posts of logged in user and people he is following orderby date
Hello everyone,
In short , I am trying to show the posts of user and his followers ordering by latest date. Exactly like Facebook feed.
I have User model with followers and posts methods as follows
public function followers()
{
return $this->belongsToMany('App\User','followers','leader_id','follower_id');
}
public function posts()
{
return $this->hasMany('App\Post');
}
also I have Post model
now I am trying to fetch posts of logged in user and his followers, I tried many ways but couldn't crack it, please help me with this. Thanks in advance for the community with great people
I have managed to get this but please let me know if there is a better solution, I have a feeling that my solution is not right, I want to run with single eloquent if possible...
yeah looks almost like my answer but I see you are not attaching logged in user id and also pluck which I see a better alternative, thanks for your answer :)
I am going to update this
Yeah no worries! You posted while I was typing lol Cheers! Yeah that would be great if there was a single query, If you come across one please share :)
i have my post returned API but i only have the user_id and contents of the post but not the name and photo of the author, its on the User model. how am i going to append another json attriubte the name and photo .