Solution:
You can use something like this:
$data = [
[
'id' => 1,
'start_date' => '2014-10-17 00:00:00',
],
[
'id' => 2,
'start_date' => '2014-10-25 00:00:00',
],
[
'id' => 3,
'start_date' => '2014-11-01 00:00:00',
],
[
'id' => 4,
'start_date' => '2014-11-13 00:00:00',
],
[
'id' => 5,
'start_date' => '2014-12-16 00:00:00',
]
];
$month = '';
use Carbon\Carbon;
foreach ($data as $item) {
$date = new Carbon($item['start_date']);
if ($date->format("F") != $month) {
$month = $date->format("F");
echo '<h1>'.$month.'</h1>';
}
echo $item['id']."<br />";
}
Of course it’s PHP code, you can first save this data and then assign it to Blade or template in other format.
You could do it this way for Blade:
$data = [
[
'id' => 1,
'start_date' => '2014-10-17 00:00:00',
],
[
'id' => 2,
'start_date' => '2014-10-25 00:00:00',
],
[
'id' => 3,
'start_date' => '2014-11-01 00:00:00',
],
[
'id' => 4,
'start_date' => '2014-11-13 00:00:00',
],
[
'id' => 5,
'start_date' => '2014-12-16 00:00:00',
]
];
$months = '';
foreach ($data as $item) {
$date = new Carbon($item['start_date']);
$months[$date->format("F")][] = $item;
}
return View::make('dates')->with('months',$months);
And in Blade:
@foreach ($months as $month => $items)
<h1>{{{ $month }}}</h1>
@foreach ($items as $item)
{{{ $item['id'] }}}<br />
@endforeach
@endforeach