我有两个查询。
$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对数据库中的数据进行计数。
POPMUISE
沧海一幻觉