Laravel: 无法显示 blade 中的数组值
Laravel: Can't display array value in blade
我将 json 存储在我的数据库中,并使用我的模型以解码格式检索它。
我将值传递给 blade 并尝试在那里显示 json 的值。
我 dd($properties)
得到这个:
array:1 [
"like" => 10
]
这有效:{{dd($properties["like"])}}
得到正确的整数值 10
但是当我 {{$properties["like"]}}
它 returns "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"];
}
我将 json 存储在我的数据库中,并使用我的模型以解码格式检索它。 我将值传递给 blade 并尝试在那里显示 json 的值。
我 dd($properties)
得到这个:
array:1 [
"like" => 10
]
这有效:{{dd($properties["like"])}}
得到正确的整数值 10
但是当我 {{$properties["like"]}}
它 returns "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"];
}