public function store() { $data = Input::all(); //return json_encode($data); $material = new Material(); $material->fill($data['material']); $material->save(); if (isset($data['vinculaciones'])) { foreach ($data['vinculaciones'] as $index => $v_data) { $vinculacion = new MaterialVinculacion(); $vinculacion->fill($v_data); $vinculacion->save(); $material->vinculaciones()->save($vinculacion); } } return Redirect::route('materiales.index'); }