所以,基本上公司可以有一个,两个或没有董事,我想根据公司简介进行展示。我想要显示如下表格(请不要介意红色边框,我只是想突出我在表格中想要改变的内容): -
这是我在表格内显示的循环:
<table class="table table-borderless table-sm table_view2">
<thead>
<tr class="spaceSmall">
<td style="width:50%;padding-left: 10px;">NOTES TO ACCOUNT<br>Schedules referred to above and notes attached there to form an integral part of Balance Sheet.<br>This is the Balance Sheet referred to in our Report of even date.</td>
<td style="width:25%"></td>
<td style="width:25%"></td>
</tr>
</thead>
<tbody>
<tr class="spaceSmall">
<td style="padding-left: 25px;">{{ $auditor->auditor_name }}<br>{{ $auditor->qualification }}<br>Membership No. : {{ $auditor->membership_number }}</td>
@foreach($tasks->work->company->directors as $director)
@if($director->pivot->director_type == 'Both' || $director->pivot->director_type == 'Director')
@if(count($director) == 1)
<td></td>
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
@elseif(count($director) == 2)
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
@else
<td></td>
<td></td>
@endif
@else
<td></td>
<td></td>
@endif
@endforeach
</tr>
</tbody>
</table>
如果公司没有董事或者公司有1名董事,那么它工作得很好,但如果公司有2名董事,那么它会尝试插入第3和第4列,但我没有第4列,如果我删除if
内部的foreach
条件然后它显示像第一张图像但我必须检查他们有的director(s)
。
提前致谢
我得到了答案,对于任何寻求答案的人我只是把这一行放在循环之外然后一切正常。
@php $countDirector = count($tasks->work->company->directors); @endphp
在我的foreach
里面
@if($countDirector == 1)
<td></td>
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
@elseif($countDirector == 2)
<td>{{ $director->salutation }} {{ $director->first_name }} {{ $director->last_name }}<br>DIRECTOR<br>{{ $director->din }}</td>
@else
<td></td>
<td></td>
@endif