使用 stream-laravel 时获取新关注的通知提要时出现问题
Having issues getting the notification feed for new follows when using stream-laravel
我正在使用 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();
}
不确定我是否遗漏了什么,但我无法获得通知源的结果。如果我从 Stream 仪表板转到资源管理器选项卡,我可以看到我有两个新的关注,它们生成了时间线和 timeline_aggregated 类型的提要。或者我应该如何从控制器操作中获取通知提要?提前致谢
\FeedManager::followUser
方法创建了两个跟随关系:时间线到用户和 timeline_aggregated 到用户。
在这种情况下,您希望在通知和用户之间创建跟随关系。应该这样做:
\FeedManager:: getNotificationFeed($request->user()->id)
.followFeed('user', $follow->target_id)
我正在使用 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();
}
不确定我是否遗漏了什么,但我无法获得通知源的结果。如果我从 Stream 仪表板转到资源管理器选项卡,我可以看到我有两个新的关注,它们生成了时间线和 timeline_aggregated 类型的提要。或者我应该如何从控制器操作中获取通知提要?提前致谢
\FeedManager::followUser
方法创建了两个跟随关系:时间线到用户和 timeline_aggregated 到用户。
在这种情况下,您希望在通知和用户之间创建跟随关系。应该这样做:
\FeedManager:: getNotificationFeed($request->user()->id)
.followFeed('user', $follow->target_id)