Я работаю над проектом, и мой код начинает запутываться.
В настоящее время у меня на контроллере есть следующее
$rollmonth = Rollmapping::latest()->value('roll_month');
$officerwk1 = DB::table('roll')
->join('rollmapping', "roll.roll_id", "=", "rollmapping.id")
->join('members', 'roll.member_id', '=', 'members.id')
->where('rollmapping.roll_month','=', $rollmonth)
->where('roll.status', '!=', 'A')
->where('members.rank', '<', 12)
->where('rollmapping.roll_week', '=', 1)
->get();
Проблема в том, что я собираюсь повторить это5 раз (для каждой недели месяца). Единственное изменение:
->where('rollmapping.roll_week', '=', 1)
для каждой недели 1, 2, 3, 4, 5,
. Я также повторял бы для каждогоГруппа рангов (которая их равна 4)
Например, WO / TO будет иметь следующее:
->wherebetween('members.rank', [12,13])
НКО будет иметь следующее:
->wherebetween('members.rank', [14,18])
Кадеты будутиметь следующее:
->where('members.rank', '>', 18)
Это приведет к 25 различным переменным, что не подходит. Должен быть лучший способ с использованием модели
Roll Table
|id|roll_id|member_id|status|
Таблица сопоставления
|id|roll_date|roll_year|roll_month|roll_week|
Таблица участников
|id|first_name|last_name|rank|.....
Конечно, должно быть лучшее решение дляукажите 25 различных переменных, которые будут отображаться в виде числа, такого как
| |Week 1|Week 2|Week 3|week 4|week 5|Totals|
|Offciers |Count Count Count Count Count |Total |
|TO/WO |Count Count Count Count Count |Total |
|NCO's |Count Count Count Count Count |Total |
|Cadets |Count Count Count Count Count |Total |
|Total |Total Total Total Total Total |Total |
В данный момент моя таблица выглядит следующим образом;
<table class="table">
<tr>
<th class="text-center">Details</th>
<th class="text-center">Week 1</th>
<th class="text-center">Week 2</th>
<th class="text-center">Week 3</th>
<th class="text-center">Week 4</th>
<th class="text-center">Week 5</th>
<th class="text-center">Total</th>
</tr>
<tr>
<th class="text-center">Officer:</th>
<td class="text-center">{{$officerwk1->count()}}</td>
<td class="text-center">{{$officerwk2->count()}}</td>
<td class="text-center">{{$officerwk3->count()}}</td>
<td class="text-center">{{$officerwk4->count()}}</td>
<td class="text-center">{{$officerwk5->count()}}</td>
<td class="text-center">{{$totalofficer->count()}}</td>
</tr>
<tr>
<th class="text-center">TO/WO:</th>
<td class="text-center">{{$towk1->count()}}</td>
<td class="text-center">{{$towk2->count()}}</td>
<td class="text-center">{{$towk3->count()}}</td>
<td class="text-center">{{$towk4->count()}}</td>
<td class="text-center">{{$towk5->count()}}</td>
<td class="text-center">{{$totalto->count()}}</td>
</tr>
<tr>
<th class="text-center">NCO:</th>
<td class="text-center">{{$ncowk1->count()}}</td>
<td class="text-center">{{$ncowk2->count()}}</td>
<td class="text-center">{{$ncowk3->count()}}</td>
<td class="text-center">{{$ncowk4->count()}}</td>
<td class="text-center">{{$ncowk5->count()}}</td>
<td class="text-center">{{$totalnco->count()}}</td>
</tr>
<tr>
<th class="text-center">Cadets:</th>
<td class="text-center">{{$cadetwk1->count()}}</td>
<td class="text-center">{{$cadetwk2->count()}}</td>
<td class="text-center">{{$cadetwk3->count()}}</td>
<td class="text-center">{{$cadetwk4->count()}}</td>
<td class="text-center">{{$cadetwk5->count()}}</td>
<td class="text-center">{{$totalcadet->count()}}</td>
</tr>
<tr>
<th class="text-center">Total:</th>
<td class="text-center">{{$totalwk1->count()}}</td>
<td class="text-center">{{$totalwk2->count()}}</td>
<td class="text-center">{{$totalwk3->count()}}</td>
<td class="text-center">{{$totalwk4->count()}}</td>
<td class="text-center">{{$totalwk5->count()}}</td>
<td class="text-center">{{$total->count()}}</td>
</tr>
</table>
Любая помощь будет отличной