有時 $structures 數組具有 null 值,其他變量的相同代碼工作正常但在這種情況下不是。@foreach($structures ?? [] as $item) {{ $item }}@endforeach
2 回答

忽然笑
TA貢獻1806條經驗 獲得超5個贊
使用forelse 而不是foreach
@forelse ($structures as $item)
{{ $item }}
@empty
No Items found.
@endforelse
檢查forelse條件如下。
@if ($structures->count())
@foreach ($structures as $item)
{{ $item }}
@endforeach
@else
No Items found.
@endif

qq_遁去的一_1
TA貢獻1725條經驗 獲得超8個贊
()我通過添加周圍表達式解決了這個問題$structures ?? []。
@foreach(($structures ?? []) as $item)
{{ $item }}
@endforeach
- 2 回答
- 0 關注
- 123 瀏覽
添加回答
舉報
0/150
提交
取消