【问题标题】:A non-numeric value encountered in Laravel scriptLaravel 脚本中遇到的非数字值
【发布时间】:2019-05-28 02:17:48
【问题描述】:

在页面上的我的 Laravel 脚本中出现此错误:

“遇到非数字值(查看:/home/grammer/public_html/test/core/resources/views/admin/apiServices.blade.php)”

对于这一行

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

我的页面代码:

@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

【问题讨论】:

  • 你定义的行是什么$items
  • 在这个页面中,我们可以看到一个站点服务及其api,项目是站点中的服务

标签: php laravel laravel-5


【解决方案1】:

只需添加这个:

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

添加:

$key = (int) $key; // GET NUMBER FROM VARIABLE

【讨论】:

  • tnx,它有效,但现在出现:Trying to get property 'service' of non-object (View: /mylocal/core/resources/views/admin/apiServices.blade.php)" 这条线:&lt;td&gt;{{ isset($item-&gt;service-&gt;id) ? $item-&gt;service-&gt;id : $item-&gt;service}}&lt;/td&gt;
  • 尝试使用$item['service'] ?或$item['service']-&gt;id ?类似的东西:)
  • 啊!只需创建一个新问题并添加您从 dd($item) 获得的所有结果;)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-12-29
  • 1970-01-01
相关资源
最近更新 更多