【问题标题】:Laravel 5.5 how can access to one value of an array in blade viewLaravel 5.5 如何在刀片视图中访问数组的一个值
【发布时间】:2020-08-17 03:52:51
【问题描述】:

我需要从刀片视图中的数组访问一个值。 我来自控制器的数组:

array:2 [▼
"chartAllAlarm" => alarmDashboardChart {#298 ▶}
"prodCounter" => array:1 [▼
  0 => {#303 ▼
  +"production": 3580
  +"preProduction": 0
  +"test": 0
  +"maintenance": 6
  +"decommissioned": 403
}

] ]

我的看法:

<h3 class="font-weight-semibold mb-0">{{ $prodCounter[production] }}</h3>    

Laravel 中的错误:

使用未定义的常量生产 - 假设“生产”(观点:

有人可以帮我吗?

【问题讨论】:

  • 您错过了$prodCounter[production] 上的报价。试试$prodCounter['production']
  • 但是如果你显示的是$prodCounter的转储,你必须访问$prodCounter['prodCounter'][0]-&gt;production之前的先前索引并访问生产属性,因为你有一个对象
  • 使用 {{ $prodCounter['prodCounter'][0]->production }} Laravel 说:未定义索引:prodCounter(查看:
  • 嗯...然后试试$prodCounter[0]-&gt;production

标签: arrays laravel laravel-blade


【解决方案1】:

我试试:

<h3 class="font-weight-semibold mb-0">{{ $prodCounter['production'] }}</h3>    

而 Laravel 返回此错误:

未定义索引:生产(查看:

好吧,我使用集合而不是数组来解决它。在恢复视图中,数据如下所示:

{{ $prodCounter->production }}    

感谢大家的支持。问候

【讨论】:

    【解决方案2】:

    你在后端使用 guzzle 吗?

    我在blade.php中有这样的代码

     <div class="col-md-2">
                <label for="PreviredID">ID Registro</label>
                <input type="int" name="PreviredID" readonly required value="{{ $posts->PreviredID}}" class="form-control">   
                <h3></h3>
            </div>
    

    你可以试试这个!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-10-22
      • 2020-01-12
      • 2021-07-06
      • 2019-09-28
      • 2019-05-08
      • 1970-01-01
      • 2018-11-26
      • 1970-01-01
      相关资源
      最近更新 更多