我有问题。Blade 没有执行 @else 语句中的代码。这是我的代码(也是一个表格):
@extends('base')
@section('title', 'Who is online?')
@endsection
@section('main')
<div class="doc-content-box">
<table class="table table-striped table-condensed">
<thead>
<tr>
<th>#</th>
<th>Name</th>
<th>Level</th>
<th>Vocation</th>
<th>Date registered</th>
<th>Role</th>
</tr>
</thead>
<tbody>
@if(!empty($results))
<?php $count = 0;?>
@foreach($results as $result)
<?php $count++;?>
<tr>
<td>{{ $count }}. </td>
<td>{{ $result->name }}</td>
<td>{{ $result->level }}</td>
<td><?php if($result->vocation == 1){
echo "Sorcerer";
}else if($result->vocation == 2){
echo 'Druid';
}else if($result->vocation == 3){
echo 'Paladin';
}else if($result->vocation == 4){
echo 'Knight';
}else if($result->vocation == 5){
echo 'Master Sorcerer';
}else if($result->vocation == 6){
echo 'Elder Druid';
}else if($result->vocation == 7){
echo 'Royal Paladin';
}else{
echo 'Elite Knight';
}?></td>
<td>{{ $result->created_at }}</td>
<td><?php if($result->group_id == 1){
echo "Player";
}else if($result->group_id == 2){
echo 'Gamemaster';
}else if($result->group_id == 3){
echo 'God';
}?></td>
</tr>
@endforeach
@else
<td>{{ "There are no users online." }}</td>
@endif
</tbody>
</table>
</div>
</div>
@endsection
它只是不会执行 没有在线玩家。我也尝试在两者之间添加它<tr></tr>
,还查看了Blade 模板未执行 @else 子句,尝试了类似:<td>'There are no players online.'</td>
,但仍然没有出现。
另外,我可以用三元运算符切换所有这些 php if 语句吗?如果是这样,我该怎么做?