我正在尝试创建收藏并将其传递给刀片。我的PHP代码看起来象Laravel - 此收藏实例上不存在属性[名称]
$collection1 = collect(['name' => 'Alex', 'id' => '1']);
$collection2 = collect(['name' => 'John', 'id' => '2']);
$collection3 = collect(['name' => 'Andy', 'id' => '3']);
$people_col = new Collection();
$people_col->push($collection1);
$people_col->push($collection2);
$people_col->push($collection3);
return view('test',[
'people_col' => $people_col
]);
在我的刀我遍历people_col
获得项目的性质:
@foreach ($people_col as $people)
<tr>
<td>{{ $people->name }}</td>
<td>{{ $people->id }}</td>
</tr>
@endforeach
但是我得到这个错误:
Property [name] does not exist on this collection instance
任何想法? 感谢
恩,先尝试'dd($ people_col)',看看它是怎么样的。 –