php - 如何在第三个关系中传递参数,当我们从第二个关系中获取值时?
问题描述
我们得到一种关系。现在我们在关系上设置条件以获取状态并针对每个案例一一检查。获取状态类型后,状态类型的值将传递给另一个关系。我们应该怎么做?下面是一个例子。
/////// Model function use for relationship//////
public function Name($statusType){
$value='';
switch ($statusType){
case 0:
$value= $this->belongsTo(/////code//////);
break;
case 1:
$value= $this->belongsTo(/////code//////);
break;
case 6:
$value= $this->belongsTo(/////code//////);
break;
case 2:
$value= $this->belongsTo(/////code//////);
break;
case 3:
$value= $this->belongsTo(/////code//////);
break;
case 4:
$value= $this->belongsTo(/////code//////);
break;
}
return $value;
}
这是我的控制器功能
$Variable = ModelName::where('id', $id])->with(['RelationShipName' => function ($query) use ($startDate) {
$query->whereDate('date', '>=', $startDate)->orderBy('date', 'DESC');
},'RelationShipName.anotherRelationShipName'])->get();
例子
$Variable = ModelName::where('id', $id])->with(['RelationShipName' => function ($query) use ($startDate) {
////how to get statusType and pass argument///
$query->whereDate('date', '>=', $startDate)->orderBy('date', 'DESC');
},'RelationShipName.anotherRelationShipName(argument)'])->get();
解决方案
推荐阅读
- swift - 如何使用 PureLayout 将标签分开
- javascript - JavaScript Web API 是否在与调用堆栈线程不同的线程上运行?
- iphone - iPhone 6 转 macbook pro 无线调试无需连接线
- ethereum - web3.eth.abi.decodeLog 返回不正确的日志参数值
- pandas - 我们应该使用 pandas.compat.StringIO 还是 Python 2/3 StringIO?
- laravel - Paypal Sandbox:抱歉,我们目前无法完成您的购买
- php - php7.2 fpm无法安装redis
- f# - F# 序列化:TypedReferences 中的字段不能是静态的或仅初始化的
- javascript - 不正确的文件上传时模态不会呈现
- jssor - 使滑块图像淡出