显示刀片文件时出现错误 '' count(): 参数必须是实现 Countable ''

我在返回网站上的视图时遇到问题,我不断收到此错误


ErrorException

count(): Parameter must be an array or an object that implements Countable (View: C:\xampp\htdocs\cargo\resources\views\shipment\single.blade.php)

这个错误指向我的刀片文件中导致该错误的部分,下面是我的视图刀片文件


 <div class="card" >

    <div class="card-body ">

        @if(count($shipment) >0)

       @foreach($shipment as $shipment)


                <div class="shipment-number">

        <span class="title" style="display: block; font-size: 25px!important;">{{$shipment->tracking_code }}</span>

    </div><!-- Track_Num -->

</div>

<br><br>


<div id="shipper-info" class="row" >

        <div class="col-md-6 detail-section">

            <p class="shipper details"><strong>Shipper's Information</strong></p>

            <div class="shipper details">

            <p><span class="label">Shipper Name : </span>{{$shipment->sender_name }}</p>

            <p><span class="label">Phone Number : </span>{{$shipment->telephone }}</p>

            <p><span class="label">Email : </span>{{$shipment->sender_email }}</p>

            <p><span class="label">Address : </span>{{$shipment->sender_address }}</p>            

        </div>

    </div>

            <div class="col-md-6 detail-section">

            <p class="shipper details"><strong>Receiver's Information</strong></p>

            <div class="receiver details">

            <p><span class="label">Receiver Name : </span>{{$shipment->receiver_name }}</p>

            <p><span class="label">Phone Number : </span>{{$shipment->receiver_telephone }}</p>

            <p><span class="label">Address : </span>{{$shipment->receiver_address }}</p>

            <p><span class="label">Email : </span>{{$shipment->receiver_email }}</p>        

        </div>

    </div>

        <div class="clear-line"></div>

</div>

@endforeach

@esle

@endif

并且错误指向此部分


@if(count($shipment) >0)

       @foreach($shipment as $shipment)


吃鸡游戏
浏览 128回答 3
3回答

开心每一天1111

您不需要对单个记录应用循环,因为您可以看到它是单个记录。<div class="card" >&nbsp; &nbsp; &nbsp; &nbsp; <div class="card-body ">&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="shipment-number">&nbsp; &nbsp; &nbsp; &nbsp; <span class="title" style="display: block; font-size: 25px!important;">{{$shipment->tracking_code }}</span>&nbsp; &nbsp; </div><!-- Track_Num --></div><br><br><div id="shipper-info" class="row" >&nbsp; &nbsp; &nbsp; &nbsp; <div class="col-md-6 detail-section">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p class="shipper details"><strong>Shipper's Information</strong></p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="shipper details">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Shipper Name : </span>{{$shipment->sender_name }}</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Phone Number : </span>{{$shipment->telephone }}</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Email : </span>{{$shipment->sender_email }}</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Address : </span>{{$shipment->sender_address }}</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="col-md-6 detail-section">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p class="shipper details"><strong>Receiver's Information</strong></p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <div class="receiver details">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Receiver Name : </span>{{$shipment->receiver_name }}</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Phone Number : </span>{{$shipment->receiver_telephone }}</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Address : </span>{{$shipment->receiver_address }}</p>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; <p><span class="label">Email : </span>{{$shipment->receiver_email }}</p>&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; </div>&nbsp; &nbsp; </div>&nbsp; &nbsp; &nbsp; &nbsp; <div class="clear-line"></div></div>

翻阅古今

您的调用->first()将返回一批货件而不是一批货件,您可以使用->get()或->paginate()获取模型的集合,然后在您的视图中迭代它们。

忽然笑

获取数据时删除->first(),->get() or ->paginate(x)改为使用,这样您就可以获得集合。在刀片文件中,foreach循环使用相同的变量作为集合和单个数据@foreach($shipment&nbsp;as&nbsp;$shipment)我建议您使用$shipments集合作为变量,并使用 $shipment 作为实例。x 只是一个数字
打开App,查看更多内容
随时随地看视频慕课网APP