当前位置: 首页 > 知识库问答 >
问题:

使用stream laravel时,在获取新follows的通知提要时遇到问题

符功
2023-03-14

我正在使用Getstream Laravel包构建一个小项目。但是,我在尝试显示新关注者的通知时遇到问题。调用FeedManager::getNotificationFeed($请求)时,我得到一个空结果集-

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中的follow和unfollow操作如下所示:

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 dashboard转到explorer选项卡,我可以看到我得到了两个新的follows,它们生成了timeline和timeline\u聚合类型的提要。或者,我应该如何从控制器操作获取通知提要?提前感谢

共有1个答案

微生毅
2023-03-14

FeedManager::followUser方法创建两个follow关系:timeline-to-user和timeline\u-aggregated-to-user。

在这种情况下,您希望在通知和用户之间创建一个follow关系。像这样的事情应该可以做到:

\FeedManager:: getNotificationFeed($request->user()->id)
    .followFeed('user', $follow->target_id)
 类似资料:
  • 问题内容: 这个问题已经在这里有了答案 : mysqli_fetch_assoc()期望参数/调用成员函数bind_param()错误。如何获取并修复实际的mysql错误? (1个答案) 4个月前关闭。 问题出在这里:我今天开始使用mysqli进行交换。没什么大不了的,只需要更改一些声明即可。一切正常,没有错误…除了我根本无法执行任何查询。我已经检查过两次和三次。我什至开始创建一种情况,它应该返回

  • 我正在开发一个需要知道用户正在听什么音乐的应用程序。 对于默认的音乐播放器,我可以收听广播,以知道正在播放哪些歌曲。 这在使用之前是有效的,但最近已经停止了。 是我使用了错误的意图筛选器还是有不同的问题?

  • 编辑:我刚刚意识到,即使是一个带有应用程序条的简单屏幕,也会发生这种情况 错误:任务“:app:checkdebugaarmadata”的执行失败 无法解析配置“:app:debugRuntimeClasspath”的所有文件。无法解析com。谷歌。firebase:firebase firestore:22.1.2。所需人员:项目:应用程序 无法解析com。谷歌。firebase:firebas

  • 我使用的是macOS版本12.0.1。所以,发生的是,我重新安装了XAMPP,所以当我点击开始时,它开始了,并显示了我的IP地址。接下来,当我去服务并试图启动所有Apache、MySQL和ProFTPD时,它们都没有启动,日志中写道: 所以,当我不知所措时,我决定检查Lampp中的文件。因此,我安装了XAMPP,然后单击了Lampp,它显示了以下文件: XAMPP文件 应该还有这么多文件,但这里没

  • 我使用的是JAX-RS注解,但我遇到了@BeanParam的问题。我用的是Wildfly-Swarm和maven。以下几行是我错误的一部分:

  • 我肯定以前在某些情况下有人问过这个问题,但是在尝试了一些关于不同问题的建议解决方案后,我不确定我一开始是否问对了问题,但这是我的情况。 我已经在C:/Users/admin/ABC下克隆了几个月的ABC项目。一切正常,我正在使用Git Bash(在Windows上)推送 此外,我如何确保我的XAMPP设置和localhost在DEF目录分离后可以很好地工作?如何在项目之间切换?我一直在努力联系我的