Q:

PHP Laravel how to group date data into months and add Header

I'm building a small Laravel-app where I want to display specific releases grouped by the month. Something like this:
January
11.1 - blabla
       more blablabla the same day

15.1 - blablabla

February
05.2 - blabla

etc...

So, In my Controller I just do this:
public function index() {

  $releases = Release::orderBy('release_date', 'asc')->get();

  return view('pages.index')->with('releases', $releases);
}

And In my blade view file I lopp through the data:
@foreach ($releases as $release)
     <div>
        <p>
            <span>{{ \Carbon\Carbon::parse($release->release_date)->format('d. M')}}</span>&nbsp;
            <span>{{$release->artist}} - {{$release->album_title}} </span>
        </p>
    </div>
@endforeach

This gives me the correct data e.g a list of the DB-entries but as mentioned before, I want to group them by month and additionally add a header for each month.  How can I achieve that? 
I'm using Laravel 5.5 if that matters...

A:

public function index() {

    $releases = Release::orderBy('release_date', 'asc')
            ->get()->groupBy('release_date.month');

    return view('pages.index')->with('releases_groups', $releases);
}

@foreach ($releases_groups as $month => $releases_group)
    // just place group info here...
    @foreach ($releases_group as $release)
    <div>
        <p>
          <span>{{ \Carbon\Carbon::parse($release->release_date)->format('d. M')}}</span>&nbsp;
          <span>{{$release->artist}} - {{$release->album_title}} </span>
        </p>
    </div>
  @endforeach
@endforeach

Try this.

