我正在使用Getstream Laravel包构建一个小项目。但是,我在尝试显示新关注者的通知时遇到问题。当我在控制器方法中调用\FeedManager::getNotificationFeed($request->user()->id)->getActivities()
时,我得到一个空结果集。我的follow
模型看起来像这样:
class Follow extends Model
{
protected $fillable = ['target_id'];
public function user()
{
return $this->belongsTo(User::class);
}
public function target()
{
return $this->belongsTo(User::class);
}
public function activityNotify()
{
$targetFeed = \FeedManager::getNotificationFeed($this->target->id);
return array($targetFeed);
}
}
然后控制器动作获取新的通知如下:
public function notification(Request $request)
{
$feed = \FeedManager::getNotificationFeed($request->user()->id);
dd($feed->getActivities());
$activities = $feed->getActivities(0,25)['results'];
return view('feed.notifications', [
'activities' => $activities,
]);
}
在用户模型中,我定义了一个用户有很多关系。最后,FollowController
中的跟随和取消关注操作如下所示:
public function follow(Request $request)
{
// Create a new follow instance for the authenticated user
// This target_id will come from a hidden field input after clicking the
// follow button
$request->user()->follows()->create([
'target_id' => $request->target_id,
]);
\FeedManager::followUser($request->user()->id, $request->target_id);
return redirect()->back();
}
public function unfollow($user_id, Request $request)
{
$follow = $request->user()->follows()->where('target_id', $user_id)->first();
\FeedManager::unfollowUser($request->user()->id, $follow->target_id);
$follow->delete();
return redirect()->back();
}
不确定是否遗漏了某些内容,但我无法获得通知Feed的结果。如果我从Stream仪表板转到explorer选项卡,我可以看到我有两个新的follow,它生成了timeline和timeline_aggregated类型的feed。或者我应该如何从控制器操作获取通知提要?提前致谢
答案 0 :(得分:0)
\FeedManager::followUser
方法创建两个关注关系:用户的时间轴和用户的timeline_aggregated。
在这种情况下,您希望在通知和用户之间创建关注关系。这样的事情应该这样做:
\FeedManager:: getNotificationFeed($request->user()->id)
.followFeed('user', $follow->target_id)