Laravel을 5.2에서 5.3으로 업그레이드했으며 블레이드보기 중 하나가 더 이상 작동하지 않습니다. 포함 된 뷰에 배열을 전달하여 루프를 반복합니다. forelse
지시문을 사용하고 있지만 정의되지 않은 오프셋 : 1 오류를 계속 표시합니다.Laravel Blade forelse에서 작동하지 않고 foreach에서 작동합니다.
$transactions = $committees->transactions()
->where('FiledDate', '<=', $to) // Upper date
->where('FiledDate', '>=', $from) // Lower date
->get();
return view('committees.show',
[
'data' => $data,
'transactions' => $transactions,
]);
는 블레이드 파일입니다 : 여기
뷰 호출로 컨트롤러 조각입니다.<table class="table table-striped">
<thead>
<tr><th class="text-center" colspan="5">Transactions</th></tr>
<tr>
<th class="text-center">TranId</th>
<th class="text-center">Tran Date</th>
<th class="text-center">SubType</th>
<th class="text-center">Filed Date</th>
<th class="text-center">Amount</th>
</tr>
</thead>
<tbody>
@forelse ($transactions AS $transaction)
<tr>
<td class="text-center">{{ $transaction->TranId }}</td>
<td class="text-center">{{ $transaction->TranDate }}</td>
<td class="text-center">{{ $transaction->SubType }}</td>
<td class="text-center">{{ $transaction->FiledDate }}</td>
<td class="text-center">{{ number_format($transaction->Amount, 2, '.', ',') }}</td>
</tr>
@empty
<tr><td colspan="5">No Transactions</td></tr>
@endforelse
</tbody>
나는 더미 트랜잭션 배열을 만든하지만 난 여전히 같은 오류가 발생했습니다.
또한 foreach
지시문을 사용하면 올바르게 작동하지만 레코드가 없는지 확인하기위한 추가 테스트가 필요합니다.
예, 나는 $ 트랜잭션 변수를 var_dumped있다. 현재 코드를 foreach로 변경하고 빈 변수를 테스트했습니다. – Mark