Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hayatu89's avatar

Nested foreach in blade templating

I am building a futsal league website where fixtures and results are to be displayed. The Result Model is like this


protected $fillable = ['team_1', 'team_2', 'goals_1', 'goals_2', 'date', 'mom'];
}

Is there a way that I can loop through this data in blade and group by date?

0 likes
6 replies
SaeedPrez's avatar
  1. This topic should not be under guides which is meant for people who write guides.
  2. Do you want to group them by date or order them by date?
  3. Just iterate through your results (assuming you're sending $teams to the view)
<table>
<tbody>
    @foreach($teams as $team)
    <tr>
        <td>{{ $team->team_1 }}</td>
        <td>{{ $team->team_2 }}</td>
        <td>{{ $team->date }}</td>
        <td>{{ $team->mom }}</td>
    <tr>
    @endforeach 
</tbody>
</table>
jlrdw's avatar

This needs to be removed from Guides

hayatu89's avatar

@SaeedPrez thanks for the reply, but what you wrote is what I had in place. What wanted to do is to group it by date, where all the matches to be played in one day will be grouped together. @ShaunL that would've been nice, but I'm using laravel 5.0 and I can't seem to find it on the docs for that version. @jlrdw yes, I habe changed it

Please or to participate in this conversation.