【问题标题】:Laravel: Can't display array value in bladeLaravel:无法在刀片中显示数组值
【发布时间】:2021-05-05 12:41:28
【问题描述】:

我将 json 存储在我的数据库中,并使用我的模型以解码格式检索它。 我将值传递给刀片并尝试在那里显示来自 json 的值。

dd($properties) 得到这个:

array:1 [
  "like" => 10
]

这有效:{{dd($properties["like"])}} 得到正确的整数值 10

但是当我执行{{$properties["like"]}} 时,它会返回"Cannot access offset of type string on string"

但是$properties 不是字符串,因为当我{{$properties}} 时,它给出了"htmlspecialchars(): Argument #1 ($string) must be of type string, array given" {{gettype($properties)}} 给了array

【问题讨论】:

  • 我对这个问题没有经验,但可能是ArrayObject,尝试通过对象表示法$properties->like访问它,或尝试$properties{"like"}

标签: laravel laravel-blade


【解决方案1】:

使用for循环

foreach($properties as $property) {
     $property["like"];
}

【讨论】:

    猜你喜欢
    • 2021-02-14
    • 2018-06-22
    • 1970-01-01
    • 2014-09-14
    • 1970-01-01
    • 2016-10-01
    • 2019-07-16
    • 1970-01-01
    • 2019-09-20
    相关资源
    最近更新 更多