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的更多相关文章

  1. jQuery Scroll Follow

    Overview Scroll Follow is a simple jQuery plugin that enables a DOM object to follow the page as the ...

  2. as follows ,as follow && following

    在现在牛津英语上,as follow 和 as follows 用法差不多的,但后者更常用,不是说谁指一个谁指好几个.牵强附会! 为了保证正确性,你应该用as follows,单数的最好少用.意义差不 ...

  3. [转]Installing python 2.7 on centos 6.3. Follow this sequence exactly for centos machine only

    Okay for centos 6.4 also On apu.0xdata.loc, after this install was done $ which python /usr/local/bi ...

  4. 编译原理LL1文法Follow集算法实现

    import hjzgg.first.First; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set ...

  5. Follow me to learn what is Unit of Work pattern

    Introduction A Unit of Work is a combination of several actions that will be grouped into a transact ...

  6. Follow me to learn what is repository pattern

    Introduction Creating a generic repository pattern in an mvc application with entity framework is th ...

  7. Follow me to learn how to use mvc template

    Introduction After having gone through many project: Project A Project B Project C I start to write ...

  8. 【转】Github轻松上手6-推荐follow的牛人和值得watch的repo

    转自:http://blog.sina.com.cn/s/blog_4b55f6860100zzk5.html Github作为一个social coding 网站,其作用远远超过了一个简单的VCS( ...

  9. To follow the path

    look to the master,    follow the master,    walk with the master,    see through the master,    bec ...

  10. first集合及follow集合

    前面那片文章生成的语法分析表并不是最优的,因为有些项在遇到错误输入的时候,并不是采取报错,而是执行规约,直到不能再规约的时候才报错.这是不科学的,我们需要在得到错误输入的时候立马报错,为了实现这个功能 ...

随机推荐

  1. HashMap的源码,实现原理,底层结构

    转载一遍不错的文章,让你深入了解HashMap http://www.cnblogs.com/ITtangtang/p/3948406.html

  2. 如何解压RPM包

    有时我们需要RPM包中的某个文件,如何解压RPM包呢? RPM包括是使用cpio格式打包的,因此可以先转成cpio然后解压,如下所示: rpm2cpio xxx.rpm | cpio -div 解压了 ...

  3. 添加,删除List<Map<String, Object>>元素

    这里讲对List<Map<String, Object>>的数据结构的添加和删除实例 添加 //初始化 List<Map<String, Object>> ...

  4. 第六天-request response\13-request乱码.avi;

    疑问:提交为POST时 ,request为什么不放在Post里面处理呢? 服务器已经启动后,修改html的代码不需要重启服务器就可以生效 :超链接中有中文,也是需要像get那样 通过该配置文件可以解决 ...

  5. Realtime Multi-Person 2D Pose Estimation using Part Affinity Fields(理解)

    0 - 人体姿态识别存在的挑战 图像中的个体数量.尺寸大小.位置均未知 个体间接触.遮挡等影响检测 实时性要求较高,传统的自顶向下方法运行时间随着个体数越多而越长 1 - 整体思路 整个模型架构是自底 ...

  6. vue WepApp 音乐App实战以及各个知识点

    1.组件初始化(scoped 貌似属于局域css样式) 2.组件使用三部曲(当然第三步可以<MHeader></MHeader> 也不报错) 3. 配置 路由 ①.在route ...

  7. redis设置开机自启

    开机自启动redis(其他服务类似) centos 7以上是用Systemd进行系统初始化的,Systemd 是 Linux 系统中最新的初始化系统(init),它主要的设计目标是克服 sysvini ...

  8. requirements.txt文件教程

    方法有2种,命令都是一样,只是执行地方不一样 此方法主要用于迁移新环境使用,为防止代码出现问题,最好使用原装库,所以就有了迁移代码和库的操作 第一种:在pycharm中,左下角有个双重正方形,点击里面 ...

  9. SQL操作json类型数据的函数

    MySQL5.7之后对json数据格式进行了函数支持 Json_contains(字段名, '值') 1.表中json格式的某个字段 2.json里的某个键值 Json_search(字段名, 'on ...

  10. linux 用户密码到期导致ftp业务失败

    外网反馈某业务失败,查看log发现FTP连接失败,定位发现提示密码不对,重新修改FTP密码后恢复正常. 但同时定位了下FTP密码被修改的原因,发现是密码过期了,因此查了下资料,查得修改过期时间的方法 ...