我正在尝试将一些数据从数据库加载到我的视图中,我已经编写了以下代码:
@forelse($wallets as $wallet)
<td>{{ $wallet->title }}</td>
<td>{{ $wallet->name }}</td>
<td>
@if(($wallet->is_active)==1)
Active
@else
Deactive
@endif
</td>
<td>
@if(($wallet->is_cachable)==1)
Cachable
@else
Un Cachable
@endif
</td>
@endforelse
但我明白这个:
语法错误,意外的"endif"(T_ENDIF)
但是,如您所见,我已经正确地关闭了if
,方法是说:@endif
那么这里出了什么问题呢?
你的@forelse
语法是错误的。
您需要在两者之间的某个位置放置一个@empty
,当$wallets
为空时将呈现该:
@forelse($wallets as $wallet)
<td>{{ $wallet->title }}</td>
<td>{{ $wallet->name }}</td>
<td>
@if(($wallet->is_active)==1)
Active
@else
Deactive
@endif
</td>
<td>
@if(($wallet->is_cachable)==1)
Cachable
@else
Un Cachable
@endif
</td>
@empty
<p>No wallet data available</p>
@endforelse
在刀片中循环。