我应该如何获取他关注的用户的帖子并使用它获取数据库的所有帖子,并给出某种条件,例如,不应该在所有帖子结果中获取关注用户帖子,所以应该首先获取它。....
我的关系:
public function following()
{
return $this->belongsToMany('App\User', 'follower_following', 'follower_id', 'following_id')
->select('id', 'uname', 'name');
}
public function posts(){
return $this->hasMany(Post::class)
->orderBy('created_at');
}
public function user()
{
return $this->belongsTo('App\User','user_id','id');
}
我已经尝试过了:
1.
$user = User::with('following.files')->get();
return response()->json(['data' => $user], 200,[],JSON_NUMERIC_CHECK);
2.
$follows = Auth::user()->following->pluck('id');
$post = Posts::whereIn('user_id',$follows)
->with('user')
->latest()
->limit(10)
->get();
just getting the auth user following post what to use to get all post with following user post