繁体   English   中英

Laravel渴望查询返回一个空列表

[英]Laravel eager query returns an empty list

我需要使用渴望的查询对laravel中的子查询进行操作,但结果始终为空。

查询:

$project = Log::where('project_id', $id)->with(['log_occurences'=> function($query){
        $query
        ->selectRaw('date(created_at) as created, count(log_id) as count')
        ->groupBy('created');
    }])

结果:

[
 {
    "id": 1,
    "title": "Haskell\\Lorna\\Moore",
    "level": "WARNING",
    "stage": "production@wenders-macbook-pro",
    "created_at": "2019-04-29 13:18:13",
    "updated_at": "2019-05-06 20:24:32",
    "log_occurences": [] <-- empty array
 },
 ...
]

我很困惑,因为我尝试了更简单的查询,例如不使用聚合并且可以工作。

请记住,在$query->selectRaw()中,主键(在这种情况下为id $query->selectRaw()对于实际检索必要的结果是必需的。*

$project = Log::where('project_id', $id)->with(['log_occurences'=>function($query){
    $query
    ->selectRaw('date(created_at) as created, count(log_id) as count,log_id')
    ->groupBy('created');
}])->get();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM