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集合
前面那片文章生成的语法分析表并不是最优的,因为有些项在遇到错误输入的时候,并不是采取报错,而是执行规约,直到不能再规约的时候才报错.这是不科学的,我们需要在得到错误输入的时候立马报错,为了实现这个功能 ...
随机推荐
- 网址,域名,IP,主机名的区别
域名 通常 Internet 主机域名的一般结构为:主机名.三级域名.二级域名.顶级域名(又称为一级域名). 二级域名及其以上级别的域名,统称为子域名,有多少个点就是几级域名 顶级域名分为两类 ...
- 今天碰到一个问题,怎么限制用户在固定宽度的input输入框里输入的长度,由此涉猎到了maxlength属性和size属性以及它们的区别。
最开始想首先要强制在一行,另外超出的隐藏.还有一个思路是把value的值的长度和框的长度怎么联系起来,具体怎么联系我也不知道. 在解决另外一个问题的时候,哥发给我的代码里无意中看见input有个max ...
- springfox-swagger2
简介 springfox是通过注解的形式自动生成API文档,利用它,可以很方便的书写restful API: swagger主要用于展示springfox生成的API文档: 依赖 <depend ...
- PTA 逆散列问题 (30 分)(贪心)
题目链接:https://pintia.cn/problem-sets/1107178288721649664/problems/1107178432099737614 题目大意: 给定长度为 N 的 ...
- 20165221 JAVA第五周学习心得
课本知识点 内部类与异常类 内部类:在一个类中定义另一个类 特点:外嵌类的成员在内部类仍然有效,内部类也可调用外嵌类的方法,内部类的类体不能声明类变量及类方法 非内部类不能是static类 匿名类:创 ...
- C++如何禁止对象的复制操作
最容易想到的是将拷贝构造函数与赋值函数声明为private.但是,private只是说外部不能直接调用,但是可以间接通过类的成员函数与友元函数对其访问.那么怎么办呢? ---->在类中,允许声明 ...
- 设计模式C++学习笔记之十一(Bridge桥梁模式)
桥梁模式,将抽象部分与它的实现部分分离,使它们都可以独立地变化.实现分离的办法就是增加一个类, 11.1.解释 main(),客户 IProduct,产品接口 CHouse,房子 CIPod,ip ...
- 效率较高的php下读取文本文件的代码
主要用下面这两个方法fread和 fgets的区别大家需要注意下 fread :以字节位计算长度,按照指定的长度和次数读取数据,遇到结尾或完成指定长度读取后停止. fgets :整行读取,遇 ...
- atom 的使用插件
emmet # html补全minimap # 源码预览图linter # 语法检查file-icons # 文件图标docblockr # 注释块autoclose-html # 自动闭合html标 ...
- zabbix添加对centos系统cpu使用率百分比的监控
cpu使用率key: system.cpu.util[] 在grafana现实的时候配置,单位选择percent(0-100),范围0-100