我有两个查询。$createdServer = Server::where('created_at', '>=', \Carbon\Carbon::now()->subMonth()) ->selectRaw('COUNT(id) as createserver, DATE(created_at) as date,DAY(created_at) as day') ->groupBy('day', 'date') ->orderBy('date', 'ASC') ->orderBy('day', 'ASC') ->get();$deletedServer = Server::where('deleted_at', '>=', \Carbon\Carbon::now()->subMonth()) ->selectRaw('COUNT(id) as deleteserver, DATE(deleted_at) as date,DAY(deleted_at) as day') ->groupBy('day', 'date') ->orderBy('date', 'ASC') ->orderBy('day', 'ASC') ->onlyTrashed() ->get();输出为: "deletedServer": [ { "deleteserver": 1, "date": "2019-04-29", "day": 29 } ], "createdServer": [ { "createserver": 2, "date": "2019-04-29", "day": 29 } ],我的要求是: "allServer": [ { "deleteserver": 1, "createserver": 2, "date": "2019-04-29", "day": 29 } ],deleteServer和createServer对数据库中的数据进行计数。
2 回答
沧海一幻觉
TA贡献1824条经验 获得超5个赞
您可以使用以下代码进行检索:
$allSevers = collect([
"deleteserver" => $deleteServer->count(), // retrieving the deleteServer count
"createserver" => $createServer->count(), // retrieving the createServer count
"date" => date('Y-m-d'), //date format in Year - Month - Date
"day" => date('j') // date format for mday
]);
- 2 回答
- 0 关注
- 191 浏览
添加回答
举报
0/150
提交
取消