0
所以我有一個像Twitter的應用程序,但我想「牆」有來自所有用戶,但以當前用戶的利益被過濾的帖子...通過用戶興趣過濾帖子?
我想要的東西,像下面這樣:
$posts = PostModel::with('interests')->latest()->get();
$user = UserModel::find(Auth::user()->id);
foreach ($posts as $post) {
foreach($user->interests as $interest){
return only the posts that have the interest_id that matches
the user's interest_ids
}
}
這是我的usermodel利益的功能:
public function interests() {
return $this->belongsToMany('InterestModel', 'users_interests', 'user_id', 'interest_id')->withPivot('interest_id');
}
這是我的興趣PostModel功能:
public function interests() {
return $this->belongsToMany("InterestModel", 'post_interest', 'post_id', 'interest_id');
}
我只是不知道如何排序和返回帖子?
感謝
馬特