douyou1901 2018-12-31 16:02
浏览 45
已采纳

Laravel脚本中遇到的非数字值

In my Laravel script on a page this error appears:

"A non-numeric value encountered (View: /home/grammer/public_html/test/core/resources/views/admin/apiServices.blade.php)"

for this line

<td>{{ $key+1 }}</td>

my page codes:

@extends('admin.layouts.master')
@section('page_icon', 'fa fa-suitcase')
@section('page_name', 'API Services')
@section('body')
    <div class="row">
        <div class="col-md-12">
            <div class="tile">
                <h3 class="tile-title">API Services List</h3>
                <table class="table table-hover">
                    <thead>
                    <tr>
                        <th>Serial</th>
                        <th>Service ID</th>
                        <th>Name</th>
                        <th>Category</th>
                        <th>Price</th>
                        <th>Min</th>
                        <th>Max</th>
                    </tr>
                    </thead>
                    <tbody>
                    @foreach($items as $key => $item)
                        <tr>
                            <td>{{ $key+1 }}</td>
                            <td>{{ isset($item->service->id) ? $item->service->id : $item->service}}</td>
                            <td>{{ $item->name }}</td>
                            <td>{{ $item->category }}</td>
                            <td>{{ isset($item->rate) ? $item->rate : $item->price_per_k }} $</td>
                            <td>{{ $item->min }}</td>
                            <td>{{ $item->max }}</td>
                        </tr>
                    @endforeach
                    </tbody>
                </table>
            </div>
        </div>
    </div>
@endsection
  • 写回答

1条回答 默认 最新

  • douchun6221 2018-12-31 18:31
    关注

    Just add this :

    <td>{{ (int) $key + 1 }}</td>
    

    or Add this:

    $key = (int) $key; // GET NUMBER FROM VARIABLE
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器