问题描述
我在循环使用 Blade 组件中的 Laravel 集合时遇到问题。我得到的错误如下。
ContentCategory::with('children')
->whereNull('parent_id')
->orderby('name')
->get();
我有一个显示 Select2 下拉列表的 Laravel Blade 组件。
<x-select2 name="user_categories" :list="$user_categories">
<x-slot name="label">
@cruds(user.fields.user_categories.text)
</x-slot>
<x-slot name="helper">
@cruds(user.fields.user_categories.helper)
</x-slot>
<x-slot name="select_all">
@globals(select_all)
</x-slot>
<x-slot name="deselect_all">
@globals(deselect_all)
</x-slot>
</x-select2>
当我遍历集合并尝试访问集合的属性时,我得到一个未定义的属性。
@foreach($list as $parent)
<option value="{{ $parent->id }}" >{{ $parent->name }}</option>
@if (isset($parent->children) && $p->children->count())
@foreach($parent->children as $children_id => $children_title)
<option value="{{ $children_id }}" {{ $isSelected($children_id) ?
'selected="selected"' : '' }}>{{ $children_title }}</option>
@endforeach
@endif
@endforeach
错误如下。
ErrorException 试图获取非对象的属性“id”(视图: /var/www/html/trybz/resources/views/components/select2.blade.PHP)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)