为什么我的foreach循环失败并显示错误“试图获取非对象的属性”:
@foreach ($memberships as $membership)
{{ $membership->id }}
@endforeach
但这很好用:
@foreach ($memberships as $membership)
<?php print_r($membership['id']); ?>
@endforeach
如果我dd($memberships);
我
array:2 [▼
0 => array:1 [▼
"id" => 8
]
1 => array:1 [▼
"id" => 9
]
]
答案 0 :(得分:2)
正如所指出的那样,我试图将数组作为对象来访问......
@foreach ($memberships as $membership)
{{ $membership['id'] }}
@endforeach