public function postBatchInsert() { foreach ($_POST as $k => $v) { foreach ($v as $k1 => $v1) { if ($k1 == 'tire_id') { $tire = Tire::select('id')->where('spec', $v1)->first(); if (!$tire) { $v1 = Tire::insertGetId(['spec' => $v1]); } else { $v1 = $tire->id; } } $insertArr[$k1] = $v1; } Detail::insert($insertArr); } }