I'm trying to figure out the best way to present data in a grouped fashion.
I have a load of courses that are displayed on the view within a @foreach( ) statement, the results are ordered by date. I have results from now up until this December for each month has quite a few records. What I'd like to do is group the month results under a header for that month, eg.
@foreach($Records as $key => $Record)
<?php $current = Date('mY', $Record->Date); ?>
@if( $key == 0 )
<?php $previous = ''; ?>
@endif
@if( $current != $previous )
<p>{{ Date('mY', $Record->Date) }}</p>
@endif
<p>Display this record for {{ $Record->id }}</p>
<?php $current = Date('mY', $Record->Date); ?>
@endforeach
This works, but I'm not overly joyed about having to embed php tags in the blade file and was just wondering if there was a better way to approach this. I've had a go at extending blade as per the documentation with not much success.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community