Php Laravel 5:从mysql数据库中的表单插入(嵌套)数组数据(从mysqli转换语法)

Php Laravel 5:从mysql数据库中的表单插入(嵌套)数组数据(从mysqli转换语法),php,arrays,laravel,nested,Php,Arrays,Laravel,Nested,我在将现有mysqli语法转换为适合Laravel的格式时遇到问题。我很乐意使用原始查询,只要它有效 我有这样一种mysqli语法(很明显,它在Laravel中不起作用): 注释中的代码 foreach ($outID as $key => $n) { DB::insert('INSERT INTO challenge_input (PropOutcomeId, ChallengeId, ChallengeUserId, InputTime, PropOutcomePts, Pro

我在将现有mysqli语法转换为适合Laravel的格式时遇到问题。我很乐意使用原始查询,只要它有效

我有这样一种mysqli语法(很明显,它在Laravel中不起作用):

注释中的代码

foreach ($outID as $key => $n) {
    DB::insert('INSERT INTO challenge_input (PropOutcomeId, ChallengeId, ChallengeUserId, InputTime, PropOutcomePts, PropId, CrushId) VALUES (?,?,?,?,?,?,?)',
        array('outID' => $outID[$key], 'chID' => $chID[$key], 'userID' => $userID[$key], 'timestamp' => $timestamp[$key], 'pts' => $pts[$key], 'prID' => $prID[$key], 'crID' => $crID[$key]));
}

数组的键必须与列名匹配:

foreach ($outID as $key => $n) {
    DB::table('challenge_input')->insert(array('PropOutcomeId' => $outID[$key], 'ChallengeId' => $chID[$key], 'ChallengeUserId' => $userID[$key], 'InputTime' => $timestamp[$key], 'PropOutcomePts' => $pts[$key], 'PropId' => $prID[$key], 'CrushId' => $crID[$key]));
}

你试过什么?您查看过Laravel查询生成器吗?我已经“翻译”了其他几个插页,效果很好。但是对于这个嵌套数据,我有一些问题。这就是我尝试过的,它给出了“无效参数号”错误:foreach($outID as$key=>$n){DB::insert('insert-INTO challenge}u输入(PropOutcomeId,ChallengeId,ChallengeUserId,InputTime,PropOutcomePts,PropId,CrushId)值(?,,,,,,,?,,,,,,,?),数组('outID=>$outID[$key],'chID'=>$chID[$chID[$key],'userID'=>$userID[$key],'timestamp'=>$timestamp[$key],'pts'=>$pts[$key],'prID'=>$prID[$key],'crID'=>$crID[$key]);}我仍然收到一个错误:“无效的参数号:未定义参数(SQL:插入到质询_输入(PropOutcomeId、ChallengeId、ChallengeUserId、InputTime、PropOutcomePts、PropId、CrushId)值中(483593AE45-b61c-11e5-a,162016-01-08 16:26:37200,35,13))。我编辑了我的答案,作为插入数组的更好(更合适)方式,而不是两次指定所有内容。艾恩伯,我可以吻你。谢谢!
foreach ($outID as $key => $n) {
    DB::insert('INSERT INTO challenge_input (PropOutcomeId, ChallengeId, ChallengeUserId, InputTime, PropOutcomePts, PropId, CrushId) VALUES (?,?,?,?,?,?,?)',
        array('outID' => $outID[$key], 'chID' => $chID[$key], 'userID' => $userID[$key], 'timestamp' => $timestamp[$key], 'pts' => $pts[$key], 'prID' => $prID[$key], 'crID' => $crID[$key]));
}
foreach ($outID as $key => $n) {
    DB::table('challenge_input')->insert(array('PropOutcomeId' => $outID[$key], 'ChallengeId' => $chID[$key], 'ChallengeUserId' => $userID[$key], 'InputTime' => $timestamp[$key], 'PropOutcomePts' => $pts[$key], 'PropId' => $prID[$key], 'CrushId' => $crID[$key]));
}