douqiang6448 2014-10-04 15:16
浏览 20
已采纳

Foreach Laravel 4

Is it just me or it's my foreach loop is acting weird. I've made a foreach to check if there is a result fetched but if there isn't, I'd be showing a notice/text acknowledging the that there are now results found. The problem here is that,I won't show any text if it doesn't return anything. What seems to be the problem here?

@extends('layouts.master')
@section('content')
     {{ Form::open(['url'=>'flight/onewayflightresults']) }}          
        <div>
            <p>Scheduled Flights</p>
        </div>
        <table class="table table-hover">
                    <th>Reserve</th>
                    <th>#</th>
                    <th>From</th>
                    <th>To</th>
                    <th>Departure</th>
                    <th>Adult</th>
                    <th>Children</th>
                    <th>Fare per person</th>
                    <th>Book Flight</th>
            @foreach($result as $row)
                @if(count($row) != 0)

                        <tr>
                            <td>{{Form::checkbox('reserve', 'value');}}</td>
                            <td>{{$row -> id}}</td>
                            <td>{{$row -> destinationfrom}}</td>
                            <td>{{$row -> destinationto}}</td>
                            <td>{{$row -> departure}}</td>
                            <td>{{{$adult}}}</td>
                            <td>{{{$child}}}</td>
                            <td>&#x20b1;{{{$row -> fare}}}</td>
                            <td>{{ Form::submit('&nbsp;&nbsp;&nbsp;&#10004;&nbsp;&nbsp;&nbsp;',array('class'=>'btn btn-success')) }}</td>
                        </tr>       
                @else 
                    <p class="bg-danger">Sorry but we have no available flight schedule on your desidered date.</p>
                @endif 
            @endforeach
       </table>
     {{ Form::close() }}
@endsection  
  • 写回答

2条回答 默认 最新

  • douaoren4402 2014-10-04 15:43
    关注

    You're trying to count $row, while it is an object. I'm not sure, but perhaps you want to do this kind of logic instead?

    @if (count($result))
        @foreach($result as $row)
            <!-- output rows -->
        @endforeach
    @else
        <!-- output no flights found -->
    @endif
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 微信公众平台自制会员卡可以通过收款码收款码收款进行自动积分吗
  • ¥15 随身WiFi网络灯亮但是没有网络,如何解决?
  • ¥15 gdf格式的脑电数据如何处理matlab
  • ¥20 重新写的代码替换了之后运行hbuliderx就这样了
  • ¥100 监控抖音用户作品更新可以微信公众号提醒
  • ¥15 UE5 如何可以不渲染HDRIBackdrop背景
  • ¥70 2048小游戏毕设项目
  • ¥20 mysql架构,按照姓名分表
  • ¥15 MATLAB实现区间[a,b]上的Gauss-Legendre积分
  • ¥15 delphi webbrowser组件网页下拉菜单自动选择问题