Facebook
From Dirga, 2 Years ago, written in PHP.
Embed
Download Paste or View Raw
Hits: 108
  1. @foreach ($programs as $program)
  2. //Looping to check the total number of Subactivities. If you have hasManyThrough Relation then this is not necessary
  3. @php
  4.         $count = 0;
  5. @endphp
  6.     @foreach($program->activities as $activity)
  7.         @foreach($activity->subactivities as $subactivity)
  8.              @php
  9.                   $count++
  10.             @endphp
  11.         @endforeach
  12.      @endforeach
  13. @php
  14.         // Creating a Check for the number of Program
  15.    $program_check = 0;
  16. @endphp
  17. @foreach($program->activities as $activity)
  18.         @php
  19.         // Creating a Check for the number of Activites
  20.         $activity_check = 0;
  21.         @endphp
  22.         @foreach($activity->subactivities as $subactivity)
  23.                 <tr>
  24.                 //If number of program is greater than 0 which will increment at the end of subactivity loop then dont   display the program again. This check will become 0 again when the next program loop begin. which is the first one
  25.                 @if ($program_check == 0)
  26.                 //Your Serial Number Counter. Replace it with your counter.
  27.                 <td rowspan="{{ $count }}">{{ $counter++ }}</td>
  28.                 <td rowspan="{{ $count }}">{{ $program->name }}</td>                                                    
  29.                 @endif
  30.                 //If number of activity greater than 0 which will increment at the end of subactivity loop then dont display the activity again. This check will become 0 again when the next activity loop begin. which is the second one
  31.                 @if ($activity_check  == 0)
  32.                         <td rowspan="{{ $activty->subactivites->count() }}">{{ $activty->name }}</td>
  33.                 @endif
  34.                         <td>{{ $subactivites->name }}</td>
  35.                 </tr>
  36.                 @php
  37.                 $program_check++;
  38.                 $activity_check++;
  39.                 @endphp
  40. @endforeach
  41. @endforeach
  42. @endforeach