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 ...
随机推荐
- day 8 - 1 文件操作
文件操作 注意: 1. r+ 最为常用 2.encoding 的编码格式一定要与文件编码格式一致 读取 r rb #在本地创建 txt 格式的文件默认使用 gbk 格式 f = open('e:/p ...
- 【blog】好用的markdown插件 - Mditor
效果 官网地址 GitHub: https://github.com/houfeng/mditor 主页: http://houfeng.net/mditor/
- lateinit 的使用限制
呢?使用lateinit关键字 lateinit var test:String //正确lateinit val test:String //错误lateinit var test:Float // ...
- MySQL报错解决方案:2013-Lost connection to MySQL server
今天上课的时候,在搭建完MySQL测试环境中出现的问题,整理如下: 问题描述:搭建完MySQL,用远程连接工具(Navicat)连接时报错: 2013-Lost connection to MySQL ...
- JVM内存分配 -Xms128m -Xmx512m -XX:PermSize=128m -XX:MaxPermSize=512m
https://blog.csdn.net/u012882327/article/details/69525166
- Android 5.0以上Material Design 沉浸式状态栏
偶然在知乎上看到这个问题,Android 5.0 如何实现将布局的内容延伸到状态栏,之前也见过多个应用的这个功能,但是知乎上的答案却没有一个真正实现此功能的一类是把标题栏设置App主题颜色,一类是提取 ...
- SpringBoot实现标准的OAuth服务提供商
⒈添加pom依赖 <dependency> <groupId>org.springframework.boot</groupId> <artifactId&g ...
- C++ 11 snippets , 2
<1>auto ,initializer_list<T>,auto指向函数指针的简易,和typdef 定义的类型执行函数指针有多复杂. #include <iostrea ...
- LwIP Application Developers Manual5---高层协议之DNS
1.前言 lwIP提供一个基本的DNS客户端(1.3.0后引进),通过使用DNS(Domain Name System)协议来允许应用程序解决主机名到地址的转换. 在文件lwipopts.h里面定义L ...
- layout 的应用
在XAF的开发中,详细Detail 或组合DashBoard页面,需要使用 LayoutControl 进行控件排列,下面讲述如何通过写代码进行操作. 0.DevExpress 的布局控件(DevEx ...