【发布时间】:2020-06-09 23:03:26
【问题描述】:
我是 Laravel 新手,正在尝试访问集合中的项目:
$results =
[
'id' => 1,
'name' => 'Learning Laravel',
];
@php ($collection = collect($results))
@php ($value = $collection->get('name'))
什么都不返回
当我使用文档中的示例时:
@php ($collection = collect(['name' => 'taylor', 'framework' => 'laravel']))
@php ($value = $collection->get('name'))
这会返回“泰勒”
【问题讨论】:
-
而不是
collect([$results])改为collect($results) -
@Ersoy 仍然一无所获
-
你能发布
dd($collection)的输出吗? -
确保在定义
$results时它在@php 指令中 -
@ITDesigns.eu ($collection) 返回 [{"id":1,"name":"Learning Laravel"}]
标签: laravel