laravel 不理解的call方法

返回结果:

原来是调用同控制器的这四个方法之一...vendor\zhiyicx\plus-question\src\API2\Controllers\UserQuestionController.php
/**
* Get all.
*
* @author bs<414606094@qq.com>
* @param Request $request
* @param Question $questionModel
* @return Collection
*/
public function all(Request $request, QuestionModel $questionModel, int $user_id)
{
$limit = $request->query('limit', 15);
$after = $request->query('after', 0);
$questions = $questionModel->with('user')
->where('user_id', $user_id)
->when($after, function ($query) use ($after) {
return $query->where('id', '<', $after);
})
->limit($limit)
->orderBy('id', 'desc')
->get(); return $questionModel->getConnection()->transaction(function () use ($questions, $user_id) {
return $questions->map(function ($question) use ($user_id) {
$question->answer = $question->answers()
->with('user')
->orderBy('id', 'desc')
->first(); if ($question->answer) {
if ($question->answer->anonymity && $question->answer->user_id !== $user_id) {
$question->answer->addHidden('user');
$question->answer->user_id = 0;
}
$question->answer->liked = (bool) $question->answer->liked($user_id);
$question->answer->collected = (bool) $question->answer->collected($user_id);
$question->answer->rewarded = (bool) $question->answer->rewarders()->where('user_id', $user_id)->first();
} return $question;
});
});
} /**
* Get invitation questions.
*
* @author bs<414606094@qq.com>
* @param Request $request
* @param Question $questionModel
* @return Collection
*/
public function invitation(Request $request, QuestionModel $questionModel, int $user_id)
{
$limit = $request->query('limit', 15);
$after = $request->query('after', 0);
$questions = $questionModel->with('user')
->whereExists(function ($query) {
return $query->from('question_invitation')->whereRaw('question_invitation.question_id = questions.id');
})
->where('user_id', $user_id)
->when($after, function ($query) use ($after) {
return $query->where('id', '<', $after);
})
->orderBy('questions.id', 'desc')
->limit($limit)
->get(); return $questionModel->getConnection()->transaction(function () use ($questions, $user_id) {
return $questions->map(function ($question) use ($user_id) {
$question->answer = $question->answers()
->with('user')
->orderBy('id', 'desc')
->first(); if ($question->answer) {
if ($question->answer->anonymity && $question->answer->user_id !== $user_id) {
$question->answer->addHidden('user');
$question->answer->user_id = 0;
}
$question->answer->liked = (bool) $question->answer->liked($user_id);
$question->answer->collected = (bool) $question->answer->collected($user_id);
$question->answer->rewarded = (bool) $question->answer->rewarders()->where('user_id', $user_id)->first();
} return $question;
});
});
} /**
* Get reward questions.
*
* @author bs<414606094@qq.com>
* @param Request $request
* @param Question $questionModel
* @return Collection
*/
public function reward(Request $request, QuestionModel $questionModel, int $user_id)
{
$limit = $request->query('limit', 15);
$after = $request->query('after', 0);
$questions = $questionModel->with('user')
->where('user_id', $user_id)
->where('amount', '>', 0)
->whereNotExists(function ($query) {
return $query->from('question_invitation')->whereRaw('question_invitation.question_id = questions.id');
})
->when($after, function ($query) use ($after) {
return $query->where('id', '<', $after);
})
->limit($limit)
->orderBy('questions.id', 'desc')
->get(); return $questionModel->getConnection()->transaction(function () use ($questions, $user_id) {
return $questions->map(function ($question) use ($user_id) {
$question->answer = $question->answers()
->with('user')
->orderBy('id', 'desc')
->first(); if ($question->answer) {
if ($question->answer->anonymity && $question->answer->user_id !== $user_id) {
$question->answer->addHidden('user');
$question->answer->user_id = 0;
}
$question->answer->liked = (bool) $question->answer->liked($user_id);
$question->answer->collected = (bool) $question->answer->collected($user_id);
$question->answer->rewarded = (bool) $question->answer->rewarders()->where('user_id', $user_id)->first();
} return $question;
});
});
} /**
* Get other questions.
*
* @author bs<414606094@qq.com>
* @param Request $request
* @param Question $questionModel
* @return Collection
*/
public function other(Request $request, QuestionModel $questionModel, int $user_id)
{
$limit = $request->query('limit', 15);
$after = $request->query('after', 0);
$questions = $questionModel->with('user')
->where('user_id', $user_id)
->where('amount', '=', 0)
->whereNotExists(function ($query) {
return $query->from('question_invitation')->whereRaw('question_invitation.question_id = questions.id');
})
->when($after, function ($query) use ($after) {
return $query->where('id', '<', $after);
})
->limit($limit)
->orderBy('questions.id', 'desc')
->get(); return $questionModel->getConnection()->transaction(function () use ($questions, $user_id) {
return $questions->map(function ($question) use ($user_id) {
$question->answer = $question->answers()
->with('user')
->orderBy('id', 'desc')
->first(); if ($question->answer) {
if ($question->answer->anonymity && $question->answer->user_id !== $user_id) {
$question->answer->addHidden('user');
$question->answer->user_id = 0;
}
$question->answer->liked = (bool) $question->answer->liked($user_id);
$question->answer->collected = (bool) $question->answer->collected($user_id);
$question->answer->rewarded = (bool) $question->answer->rewarders()->where('user_id', $user_id)->first();
} return $question;
});
});
}
理解不了call()...暂记下来 vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php






laravel 不理解的call方法的更多相关文章
- Laravel 深入理解路由和URL生成
原文地址: Laravel 深入理解路由和URL生成 在模板中我们一般不会直接写死url,而是用url助手生成url,本文介绍一下url助手的使用以及遇到的一些比较头疼的问题. 首先,我们创建了一个路 ...
- js中的回调函数的理解和使用方法
js中的回调函数的理解和使用方法 一. 回调函数的作用 js代码会至上而下一条线执行下去,但是有时候我们需要等到一个操作结束之后再进行下一个操作,这时候就需要用到回调函数. 二. 回调函数的解释 因为 ...
- 【JVM虚拟机】(8)--深入理解Class中--方法、属性表集合
#[JVM虚拟机](8)--深入理解Class中--方法.属性表集合 之前有关class文件已经写了两篇博客: 1.[JVM虚拟机](5)---深入理解JVM-Class中常量池 2.[JVM虚拟机] ...
- 理解 ES6 Generator-next()方法
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 查看 Laravel 的 SQL 语句的方法
在使用 Laravel 的 Eloquent 进行数据查询的时候,很多小伙伴都想看到背后执行的 SQL 语句到底是什么样的,这小笔录就是解决这个小问题的: 在 Providers/AppService ...
- 连续张量理解和contiguous()方法使用,view和reshape的区别
连续张量理解和contiguous()方法使用,view和reshape的区别 待办 内存共享: 下边的x内存布局是从0开始的,y内存布局,不是从0开始的张量 For example: when yo ...
- Laravel框架中的make方法详解
为什么网上已经有这么多的介绍Laravel的执行流程了,Laravel的容器详解了,Laravel的特性了,Laravel的启动过程了之类的文章,我还要来再分享呢? 因为,每个人的思维方式和方向是不一 ...
- Laravel的三种安装方法总结
Laravel号称巨匠级PHP框架,越来越多的PHPer选择它作为开发框架,作为一个Laravel初学者相信很多人向我一样被安装挡在了门外.所以今天结合文档和自己的学习经历总结一下Laravel的安装 ...
- laravel Input Cokkie 的各种方法 超实用!!!
基本输入 Laravel使用一种简单的方式来访问用户提交的信息. 你可以用统一的方式来访问用户提交的信息,而不用为用户提交信息的方式操心. 获取一个用户提交的值 代码如下: $name = Input ...
随机推荐
- nginx常用指令
./nginx #打开 nginx nginx -s reload|reopen|stop|quit #重新加载配置|重启|停止|退出 nginx nginx -t #测试配置是否有语法错误 ngin ...
- Django学习手册 - ORM - ImageField数据类型
前置步骤 setting.py文件配置: 添加app目录 INSTALLED_APPS = [ 'django.contrib.admin', 'django.contrib.auth', 'djan ...
- Light oj 1021 - Painful Bases
题意: 给一个B进制的数,一个10进制的数K,B进制数有x位, 对着x位进行全排列的话,有x!种可能, 问这x!的可能中,有多少种可以整除K,各个位置上的数字都不同. 思路:状态压缩,数位DP #i ...
- DAC杂谈一
DAC种类: 有权电阻网络DAC 输出电压变化范围为:0~-(2^n-1)/2^n*Vref 当位数很高时,每个电阻都有很高精度是十分困难的. 倒T型电阻网络DAC(比如AD7520 10bit 已停 ...
- Pyperclip could not find a copy/paste mechanism for your system.
sudo apt-get install xsel sudo apt-get install xclip pip install gtk to install the gtk Python modul ...
- 很清晰的解读i2c协议【转】
转自:https://blog.csdn.net/weixin_41718085/article/details/79376823 转载:http://dpinglee.blog.163.com/bl ...
- mysql死锁-查询锁表进程-分析锁表原因【转】
查询锁表进程: 1.查询是否锁表 show OPEN TABLES where In_use > 0; 2.查询进程 show processlist 查询到相对应的进程===然 ...
- unity制作背景
- javascript动态的改变checkbox的选中状态
<td> <div class="checkbox"> <label> <input type="checkbox" ...
- Ubuntu 18.04使用sudo pip3报错
在使用sudo pip3 install python库的时候出现如下警告: The directory '/home/lzhu/.cache/pip/http' or its parent dire ...