我需要使用array
循环
foreach
这是我的array
看起来像
$event->menu->add( 'MEDIA' );
$event->menu->add(
[
'text' => 'About us',
'icon_color' => 'green',
'submenu' => [
[
'text' => 'menu items 1',
'icon_color' => "lime",
'url' => 'admin/link',
],
],
] );
现在我需要用来自数据库
的数据替换submenu
中的项目
这里的循环看起来像
$abouts = About::all();
foreach($abouts as $about){
[
'text' => 'About us',
'icon_color' => "lime",
'url' => 'admin/about/1/edit',
];
}
我的问题是
如何覆盖此
'submenu' => [
[
'text' => 'menu items 1',
'icon_color' => "lime",
'url' => 'admin/link',
],
],
使用我的foreach
循环
dump array看起来像这样
BuildingMenu {#256 ▼
+menu: Builder {#246 ▼
+menu: array:4 [▼
0 => "MEDIA"
1 => array:9 [▶]
2 => "MEDIA"
3 => array:12 [▼
"text" => "About us"
"icon_color" => "green"
"submenu" => array:5 [▼
0 => array:9 [▼
"text" => "About us"
"icon_color" => "lime"
"url" => "admin/about/1/edit"
"href" => "http://localhost:8000/admin/about/1/edit"
"active" => true
"classes" => array:1 [▶]
"class" => "active"
"top_nav_classes" => array:1 [▶]
"top_nav_class" => "active"
]
]
"href" => "#"
"active" => true
"submenu_open" => true
"submenu_classes" => array:1 [▶]
"submenu_class" => "treeview-menu"
"classes" => array:2 [▶]
"class" => "active treeview"
"top_nav_classes" => array:2 [▶]
"top_nav_class" => "active dropdown"
]
]
var-dump $ about
Collection {#265 ▼
#items: array:5 [▼
0 => About {#266 ▼
+translatedAttributes: array:2 [▶]
#fillable: array:1 [▶]
#connection: null
#table: null
#primaryKey: "id"
#keyType: "int"
#perPage: 15
+incrementing: true
+timestamps: true
#attributes: array:4 [▶]
#original: array:4 [▶]
#relations: []
#hidden: []
#visible: []
#appends: []
#guarded: array:1 [▶]
#dates: []
#dateFormat: null
#casts: []
#touches: []
#observables: []
#with: []
#morphClass: null
+exists: true
+wasRecentlyCreated: false
}
1 => About {#267 ▶}
2 => About {#268 ▶}
3 => About {#269 ▶}
4 => About {#270 ▶}
]
}
提前致谢
答案 0 :(得分:0)
您可以从此处获取text
密钥:
$event->menu->menu[3]['submenu'][0]['text']
icon_color
和url