1
I have this consultation using eloquent
$data= \App\Logs::select('id', 'created_at')
->get()
->groupBy(function($val) {
return Carbon::parse($val->created_at)->format('d-M-');
})->toArray();
and she returns this
array:2 [▼
"06-Jul-" => array:1 [▼
0 => array:2 [▼
"id" => 1
"created_at" => "2017-07-06 13:21:15"
]
]
"07-Jul-" => array:3 [▼
0 => array:2 [▼
"id" => 2
"created_at" => "2017-07-07 13:43:23"
]
1 => array:2 [▼
"id" => 3
"created_at" => "2017-07-07 14:18:36"
]
2 => array:2 [▼
"id" => 4
"created_at" => "2017-07-07 14:18:41"
]
]
]
when I’d like her to return
"06-Jul-" => "1"
"07-Jul-" => "3"
or something like that I don’t understand what I’m doing wrong
A simple way to get around the problem is to count the amount of elements of each date with the
count
php. Typecount($x["06-Jul-"])
– Isac
Is mysql?????...
– novic
You could edit the question and put the structure of the Logs table.
– DNick
You asked for the list of ids in select, not the count (per day). The query has a method
count
for that reason.– bfavaretto