public function addCord($id) { $pod_inventory = PodInventory::find($id); if (isset($_POST['submit'])) { $podCord_ids = array(); foreach (Input::get('name') as $key => $data) { $podCord = Cord::find(Input::get('cord_id')[$key]) ?: new Cord(); $podCord->name = $data; $podCord->pod_inventory_id = $id; $podCord->save(); $podCord_ids[] = $podCord->id; } Cord::where('pod_inventory_id', $id)->whereNotIn('id', $podCord_ids)->delete(); return Redirect::to('add-charger/' . $id); } else { $cords = $pod_inventory->cords->toArray(); return View::make('cords.multiple', compact('cords', 'pod_inventory')); } }