lundi 7 novembre 2016

How can I add a blank row at the end of this nested foreach? - Laravel Blade

I have a table of game schedules. In my controller I am doing this;

    $schedule = Schedule::where('season', '=', $season->id)
    ->where('date', '>', Carbon::now()->subDays(1))->get();

    foreach ($schedule as $item) {
        $date = new Carbon($item['date']);
        $months[$date->format("F Y")][] = $item;
    }

This allows me to then do this in my blade view;

    @foreach ($months as $month => $items)
        <tr style="background-color: rgba(101, 101, 101, 0.4);">
           <td colspan="5">
             <strong></strong>
            </td>
        </tr>
        @foreach ($items as $item)
          <tr>
            <td width="20%">/td>
            <td width="20%"></td>
            <td width="25%"><a href=""></a></td>
            <td width="25%"><a href=""></a></td>
            <td width="10%"><a href="gamesheet/" target="_blank"><i class="fa fa-print" aria-hidden="true"></i></a></td>
          </tr>
         @endforeach
      @endforeach

So far so good in that this grabs the month and creates a distinct row with the month as a heading.

Now, I would like to try to do the same with each week. To get something like this;

November 2016
Mon Nov 7 7:00PM Team A   Team B
Mon Nov 7 8:00PM Team C   Team D
<empty row here>
Mon Nov 14 7:00PM Team D Team A
Mon Nov 14 8:00PM Team B Team C
<empty row here>

I have tried defining a week array in my controller like this;

$weeks[$date->format("M j")][] = $item;

But it needs to also end the loop when the month changes. Any ideas? Should I be trying to do a further loop in the controller?

Thanks!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire