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的更多相关文章
- jQuery Scroll Follow
Overview Scroll Follow is a simple jQuery plugin that enables a DOM object to follow the page as the ...
- as follows ,as follow && following
在现在牛津英语上,as follow 和 as follows 用法差不多的,但后者更常用,不是说谁指一个谁指好几个.牵强附会! 为了保证正确性,你应该用as follows,单数的最好少用.意义差不 ...
- [转]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 ...
- 编译原理LL1文法Follow集算法实现
import hjzgg.first.First; import java.util.LinkedHashMap; import java.util.Map; import java.util.Set ...
- 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 ...
- Follow me to learn what is repository pattern
Introduction Creating a generic repository pattern in an mvc application with entity framework is th ...
- 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 ...
- 【转】Github轻松上手6-推荐follow的牛人和值得watch的repo
转自:http://blog.sina.com.cn/s/blog_4b55f6860100zzk5.html Github作为一个social coding 网站,其作用远远超过了一个简单的VCS( ...
- To follow the path
look to the master, follow the master, walk with the master, see through the master, bec ...
- first集合及follow集合
前面那片文章生成的语法分析表并不是最优的,因为有些项在遇到错误输入的时候,并不是采取报错,而是执行规约,直到不能再规约的时候才报错.这是不科学的,我们需要在得到错误输入的时候立马报错,为了实现这个功能 ...
随机推荐
- Element Select 回显
有思考有痛点的朋友可以聊聊(要求:认真看过Element相关文档,对该场景自己有过多角度的探索) 下拉框回显的关键点:要回显的值包含于下拉列表的数组中 demo图 最近遇到一个需求抽象下:循环中下拉框 ...
- Django REST framework 第二章 Request and Response
此章节开始真正的撰写REST framework的核心代码,介绍一系列必要的建立设计 Request Objects REST framework介绍了一个Request对象用来扩展常规的HttpRe ...
- Linux常用命令(三)查看当前计算机各方面信息
1.查看cpu: top 2.查看当前linux版本:name -a 查看当前运行的内核版本:cat /pro/version 查看发行版本信息:cat /etc/issue 查看上面所有信息:lsb ...
- MGR架构 ~ 节点的维护相关问题
一简介:MGR节点的相关维护二 两种情况 1 MGR读节点异常停止,然后重新启动加入节点进行数据同步 2 MGR读节点新加入集群成员,启动复制进行数据同步三 通用过程 1 新加入节点通过通道 ...
- Serializable 和Parcelable 的区别
1.作用 Serializable的作用是为了保存对象的属性到本地文件.数据库.网络流.RMI(Remote Method Invocation)以方便数据传输,当然这种传输可以是程序内的也可以是两个 ...
- 使用grep排除空行和注释行
grep的排除选项为 -v排除空行的命令是:grep -v '^$' filename排除以#注释的命令是:grep -v '^#' filename 结合起来就是,既排除空行又排除注释行的命令gre ...
- pythonの信号量
#!/usr/bin/env python import threading,time def run(n): # 申请锁 semaphore.acquire() time.sleep(1) prin ...
- IntelliJ IDEA 配置
1.让IntelliJ IDEA 驼峰选择生效 驼峰选择,就是选择的时候按照驼峰规则选择单词,不是选择整个单词 让IntelliJ IDEA 驼峰选择生效 2.查看当前类中的所有方法 Alt+7 3. ...
- Path Sum I && II & III
Path Sum I Given a binary tree and a sum, determine if the tree has a root-to-leaf path such that ad ...
- LwIP Application Developers Manual9---LwIP and multithreading
1.前言 lwIP的内核并不是线程安全的.如果我们必须在多线程环境里使用lwIP,那么我们必须使用“upper”API层的函数(netconn或sockets).当使用raw API时,你需要自己保护 ...