2つの配列が1つの連想で、2つ目は非連想です。各配列の各項目にデータベースの行として挿入します。以下のコードでは、$ menuと$ idは配列です。この$ id部分は、それ自身が配列であるので私にエラーを与えています。エラーは "配列から文字列への変換"と言います。助けてください!!!foreachループで2つの配列を反復して単一のレコードを取得する方法
foreach($menu as $label => $link) {
$id = $request->themeLocation;
DB::table('menus')->insertGetId([ 'label' => $label ,'url' => $link ,'themeLocation' => '$id ,'menu_status' => 1 ]);
}
foreachの中で、私はDB
id themeLocation url label menu_status
41 child-38 about ABOUT US 1
42 child-39 about ABOUT US 1
43 child-40 about ABOUT US 1
44 child-38 services Services 1
45 child-39 services Services 1
46 child-40 services Services 1
47 child-38 contact contact 1
48 child-39 contact contact 1
49 child-40 contact contact 1
における階層エントリをgetingですが、私は、DB内の冗長エントリを取得していますとのforeachを適用した後、私はこの結果に
41 child-38 about ABOUT US 1
42 child-39 services Services 1
43 child-40 contact contact 1
感謝をしたいです!
構文の強調表示はおそらくあなたの問題を解決しますか? –
'$ id'の前に余分な引用符があります。 – Barmar
ありがとう、どのように??? –