Laravel:无法在刀片中显示数组值

问题描述

我将 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

解决方法

使用 for 循环

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