public function groupByDate()
{
$posts = $this->post->all();
$group = [];
foreach ($posts as $post) {
$date = date_parse($post->created_at);
$mYear = $date['year'];
$mMonth = $date['month'];
// Month or Year not exists current.
if (!array_key_exists($mYear, $group)) {
$group[$mYear] = [];
}
if (!array_key_exists($mMonth, $group[$mYear])) {
$group[$mYear][$mMonth] = [];
}
array_push($group[$mYear][$mMonth], $post);
}
return view('front.archive.date', compact('group'));
}