php - 使用 hasMany 关系进行雄辩的急切加载不起作用
问题描述
我的代码目前不起作用,但我的关系是正确的。
项目模型
public function timeEntries()
{
return $this->hasMany('App\Model\TimeEntries');
}
$array_of_project = Project::with('timeEntries')
->whereBetween('spent_on', [($request->debut)), ($request->fin))])
->get();
它没有找到“spent_on”。
解决方案
看起来您正在尝试限制关系的记录。我建议查看有关限制急切加载的文档。这是我认为您正在尝试完成的代码示例:
$projects = App\Model\Project::with(['timeEntries' => function ($query) use ($request) {
$query->whereBetween('spent_on', $request->debut, $request->fin);
}])->get();
https://laravel.com/docs/5.8/eloquent-relationships#constraining-eager-loads
推荐阅读
- r - chart_Series:来自脚本时没有情节
- kubernetes - 如何使用出口网络策略允许访问 kubernetes api?
- html - ReactJS - 如何解析 JSON 元素中的 JSX 变量
- oracle - 许多人收到 SMTP 电子邮件,而其他人则没有
- r - 使用变量名称中的年份从宽到长重塑
- git - 仅将一些更改推送到远程
- c++ - 导出到 Excel 的 C++ 数组是列优先的
- python - 在 Linux 上安装 numpy、keras 和 theano,无需 root 权限
- c# - WPF:如何以任务格式从 firebase 访问数据
- javascript - 仅提取对象中具有值的属性