follow

Posted sgm4231

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了follow相关的知识,希望对你有一定的参考价值。

public function follow(Request $request, FeedModel $model, FeedRepository $repository)
    {
        if (is_null($user = $request->user(‘api‘))) {
            abort(401);
        }

        $limit = $request->query(‘limit‘, 15);
        $after = $request->query(‘after‘);
        $feeds = $model->leftJoin(‘user_follow‘, function ($join) use ($user) {
            $join->where(‘user_follow.user_id‘, $user->id);
        })
            ->whereDoesntHave(‘blacks‘, function ($query) use ($user) {
                $query->where(‘user_id‘, $user);
            })
            ->where(function ($query) use ($user) {
                $query->whereColumn(‘feeds.user_id‘, ‘=‘, ‘user_follow.target‘)
                    ->orWhere(‘feeds.user_id‘, $user->id);
            })
            ->with([
                ‘user‘ => function ($query) {
                    return $query->withTrashed();
                },
                ‘topics‘ => function ($query) {
                    return $query->select(‘id‘, ‘name‘);
                },
                ‘user.certification‘,
                ‘pinnedComments‘ => function ($query) {
                    return $query->with([
                        ‘user‘,
                        ‘user.certification‘,
                    ])
                    ->where(‘expires_at‘, ‘>‘, new Carbon)
                    ->orderBy(‘amount‘, ‘desc‘)
                    ->orderBy(‘created_at‘, ‘desc‘);
                },
            ])
            ->when((bool) $after, function ($query) use ($after) {
                return $query->where(‘feeds.id‘, ‘<‘, $after);
            })
            ->distinct()
            ->select(‘feeds.*‘)
            ->orderBy(‘feeds.id‘, ‘desc‘)
            ->limit($limit)
            ->get();

        return $feeds->map(function (FeedModel $feed) use ($repository, $user) {
            $feed->feed_view_count += 1;
            $feed->hot = $feed->makeHotValue();
            $feed->save();

            $repository->setModel($feed);
            $repository->images();
            $repository->format($user->id);
            $repository->previewComments();

            $feed->has_collect = $feed->collected($user->id);
            $feed->has_like = $feed->liked($user);

            return $feed;
        });
    }

以上是关于follow的主要内容,如果未能解决你的问题,请参考以下文章

什么?语音合成开源代码不会跑,follow me!

1124 Raffle for Weibo Followers

Cocos Creator 镜头跟随(cc.follow)

Cocos Creator 镜头跟随(cc.follow)

无法使用xpath follow-sibling获取元素

大数据基础zookeeper源代码解析