【发布时间】:2019-11-23 22:12:57
【问题描述】:
我是 Laravel 新手,这是我遇到的问题 有 3 个表具有这种关系:
AttributeGroup -> 一对多-> AttributeGroupMapping
AttributeGroupMapping -> 多对一 -> 属性
我准备了模型和控制器,我得到了这个集合:
lluminate\Database\Eloquent\Collection {#3093
all: [
App\AttributeGroup {#3085
id: 1,
name: "General",
position: 1,
is_user_defined: 0,
attribute_family_id: 1,
created_at: "2019-11-23 20:46:27",
updated_at: "2019-11-23 20:46:27",
attributeGroupMapping: Illuminate\Database\Eloquent\Collection {#3079
all: [
App\AttributeGroupMapping {#3106
attribute_id: 1,
attribute_group_id: 1,
position: 1,
created_at: "2019-11-23 20:46:27",
updated_at: "2019-11-23 20:46:27",
Attribute: App\Attribute {#3109
id: 1,
code: "phone1",
admin_name: "Phone 1",
type: "text",
validation: null,
position: 1,
is_required: 1,
is_unique: 0,
value_per_locale: 0,
value_per_channel: 0,
is_filterable: 0,
is_configurable: 0,
is_user_defined: 0,
is_visible_on_front: 0,
swatch_type: null,
use_in_flat: 1,
created_at: "2019-11-23 20:46:27",
updated_at: "2019-11-23 20:46:27",
},
},
App\AttributeGroupMapping {#3096
attribute_id: 2,
attribute_group_id: 1,
position: 9,
created_at: "2019-11-23 20:46:27",
updated_at: "2019-11-23 20:46:27",
Attribute: App\Attribute {#3117
id: 2,
code: "notes",
admin_name: "notes",
type: "textarea",
validation: null,
position: 9,
is_required: 0,
is_unique: 0,
value_per_locale: 0,
value_per_channel: 0,
is_filterable: 0,
is_configurable: 0,
is_user_defined: 0,
is_visible_on_front: 0,
swatch_type: null,
use_in_flat: 1,
created_at: "2019-11-23 20:46:27",
updated_at: "2019-11-23 20:46:27",
},
},
],
},
},
App\AttributeGroup {#3077
id: 2,
name: "Detalle",
position: 2,
is_user_defined: 0,
attribute_family_id: 1,
created_at: "2019-11-23 20:46:27",
updated_at: "2019-11-23 20:46:27",
attributeGroupMapping: Illuminate\Database\Eloquent\Collection {#3070
all: [],
},
},
],
}
现在,我怎样才能使用 foreach trow 循环 3 个级别,以便获得: ......AttributeGroup(每一个)
.............属性映射(每一个)
.......................属性(每一个)
这是我发送到视图的内容:
$attributesGroups= AttributeGroup::with('attributeGroupMapping.Attribute')->get();
return view('admin.contact-conf', compact('attributesGroups'));
我怎样才能让它工作? 谢谢
【问题讨论】:
-
刀片视图页面上有什么?应该有类似
@foreach($items as item) @endforeach
标签: laravel eloquent laravel-blade