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. day 9 - 1 函数

    函数 函数:定义了之后,可以在任何需要它的地方调用 函数模拟 len() 方法 #len() 方法的使用 s="世界上唯一不变的就是变化" print(len(s)) #下面是我们 ...

  2. Python 10 协程,异步IO,Paramiko

    本节内容 Gevent协程 异步IO Paramiko 携程 协程,又称为微线程,纤程(coroutine).是一种用户态的轻量级线程. 协程拥有自己的寄存器上下文和栈.协程调度切换时,将寄存器上下文 ...

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

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

  4. Javascript - ExtJs - Window组件

    1.所有组件都可以放入window,此时子组件不需要配置renderTo,只需要将它们作为window的items子项即可. 2.items子项必须先创建,最后创建window,否则子项不会显示. 3 ...

  5. springboot中spring.profiles.active来引入多个properties文件 & Springboot获取容器中对象

    1.    引入多个properties文件 很多时候,我们项目在开发环境和生成环境的环境配置是不一样的,例如,数据库配置,在开发的时候,我们一般用测试数据库,而在生产环境的时候,我们是用正式的数据, ...

  6. MySQL 4.1-5.0-5.1-5.5-5.6各版本的主要区别

    各版本的一些命令差异:  show innodb status\G mysql-5.1  show engines innodb status\G mysql-5.5  关于grant授权 mysql ...

  7. 在windows下用vagrant建立lnmp开发环境

    1.安装vagrant,vitrualbox 2.下载homestead的box包,并添加到vagrant 下载地址: https://atlas.hashicorp.com/laravel/boxe ...

  8. 删除元素splice、shift\pop

      splice() 方法: 向/从数组中添加/删除项目,然后返回被删除的项目. splice( index位数, 数量, 新添加 ) 该方法会改变原始数组 删除数组中第一个元素 arr.shift( ...

  9. OTP

    OTP 是 One Time Programable, 一次性可编程,一种存储器类型.顾名思义,只允许一次编程,后面无法修改. 在嵌入式系统当中,所有的代码和系统数据都是存储在flash芯片内部的,f ...

  10. 压缩JS的eclipse插件

    主页:http://jscompressor.oncereply.me/ Update site: http://jscompressor.oncereply.me/update/