Laravel 4 else statement -
i've got problem. blade not executing code within @else statement. here's code (also, it's table):
@extends('base') @section('title', 'who 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 $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 no users online." }}</td> @endif </tbody> </table> </div> </div> @endsection
it won't execute there no players online. i've tried adding in between <tr></tr>
, viewed blade template not executing @else clause , tried like: <td>'there no players online.'</td>
, still doesn't show up.
also, able switch php if statements ternary operators? if so, how it?
the reason because if
statement inside of foreach
statement , therefore never executed. if move foreach
inside of if
block, should work.
--- more
i had doing , discovered problem. calling empty()
on $results
object , not array, collection
object. proper way use count()
method. this:
@if($results->count() > 0) @foreach($results $result) ... @endforeach @else <p>nothing found!</p> @endif
Comments
Post a Comment