我有一份具有以下结构的文件
db.projects.find().pretty()
{
"_id" : ObjectId("587eb04ec5d281280d9244ed"),
"root" : "Main Boards",
"access" : "Public",
"folders" : [
{
"foldersname" : "PROJECTS"
}
]
}
{
"_id" : ObjectId("587eb052c5d281280d9244ee"),
"root" : "Shared Boards",
"access" : "Public"
}
我成功地将数据加载到变量中。我可以在刀片视图中显示字段“root”内容,但我不能显示字段'foldersname'。这是我的代码。
@foreach($structures as $structure)
<a class="mdl-navigation__link" href="">{{$structure->root}}</a>
@foreach($structure as $folders)
<a class="mdl-navigation__link" href="">{{$folders->foldersname}}</a>
@endforeach
@endforeach
我收到以下错误。我从那以后一直在寻找解决方案。我已经应用了laravel论坛和这里的解决方案但是徒劳无功。有人可以指导我找到正确的解决方案。感谢
尝试获取非对象的属性
答案 0 :(得分:1)
试试这个:
@foreach($structures as $structure)
<a class="mdl-navigation__link" href="">{{$structure->root}}</a>
@if (isset($structure->folders))
@foreach($structure->folders as $folder)
@if(isset($folder['foldersname']) )
<a class="mdl-navigation__link" href="">{{$folder['foldersname']}} </a>
@endif
@endforeach
@endif
@endforeach