我正在将 Laravel 从 5.2 升级到 5.3,并且我的 Blade 视图之一不再工作。我将一个数组传递给包含的视图以循环遍历它。我正在使用该forelse
指令,但它一直给我一个 Undefined offset: 1 错误。
这是带有视图调用的控制器片段:
$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
指令时,它可以正常工作,但是我必须进行额外的测试以检查是否没有记录。