public function importarArticulos() { $reqs = Req::whereBetween('req', $this->arr_rango)->get(['id', 'req', 'estatus']); foreach ($reqs as $req) { $articulos_legacy = $this->consultarArticulosLegacy($req->req); foreach ($articulos_legacy as $art_legacy) { if (!empty($art_legacy->oc)) { $oc_id = Oc::whereOc($art_legacy->oc)->pluck('id'); if (empty($oc_id)) { $oc_id = 0; } } else { $oc_id = 0; } $articulo = new Articulo(); $articulo->req_id = $req->id; $articulo->articulo = $art_legacy->art . ' ' . $art_legacy->esp; $articulo->cantidad = $art_legacy->cantidad; $articulo->impuesto = $art_legacy->impuesto; $articulo->monto = $art_legacy->monto; $articulo->oc_id = $oc_id; $articulo->unidad = $art_legacy->unidad; $articulo->inventariable = $art_legacy->alta; $articulo->save(); if (!empty($art_legacy->rm)) { $rm_id = Rm::whereRm($art_legacy->rm)->value('id'); $articulo->rms()->attach($rm_id, ['monto' => $art_legacy->monto]); } } } }