diff --git a/database/seeders/BarrioSeeder.php b/database/seeders/BarrioSeeder.php index 1d59a25..7fbc3f5 100644 --- a/database/seeders/BarrioSeeder.php +++ b/database/seeders/BarrioSeeder.php @@ -21,7 +21,7 @@ public function run(): void ])->id; Barrio::create([ - 'name'=>'PRUEBA','region_id'=>$prueba_id, 'created_at'=>Date::now() + 'name'=>'PRUEBA','region_id' => $prueba_id ]); } } diff --git a/database/seeders/CanastaSeeder.php b/database/seeders/CanastaSeeder.php index a61c3aa..ab8803d 100644 --- a/database/seeders/CanastaSeeder.php +++ b/database/seeders/CanastaSeeder.php @@ -37,16 +37,15 @@ public function run(): void $tipo = trim($record[$tipoColumn]); if (!in_array($tipo, $tipos)) { - if (!Str::contains($tipo,'¿') && ($tipo != 'T')) { + if (!Str::contains($tipo,'¿') && ($tipo != 'T')) $currentCategoria = Categoria::firstOrCreate(['name' => $tipo]); - } } else { - $parsed = $this->parseAndFormatName($record[$productoColumn]); + [$solidario, $name, $caracteristicas] = $this->parseAndFormatName($record[$productoColumn]); $productosToInsert[] = [ - 'name' => $parsed['name'], + 'name' => $name, 'price' => $record[$precioColumn], - 'solidario' => $parsed['solidario'], + 'solidario' => $solidario, 'bono' => $tipo == 'B', 'categoria_id' => $currentCategoria->id, 'created_at' => Date::now(), @@ -54,23 +53,22 @@ public function run(): void ]; $caracteristicasToInsert[] = [ - 'name' => $parsed['name'], - 'caracteristicas' => $parsed['caracteristicas'] + 'name' => $name, + 'caracteristicas' => $caracteristicas ]; } } - foreach (array_chunk($productosToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) { + foreach (array_chunk($productosToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk) DB::table('productos')->insert($chunk); - } $this->insertCaracteristicas($caracteristicasToInsert); } /** - * Returns an array data parsed from productoColumn. + * Returns an array with data parsed from productoColumn. * - * @return array{solidario: bool, name: string, caracteristicas: array(Caracteristica)} + * @return array{solidario: bool, name: string, caracteristicas: array(Caracteristica->id)} */ private function parseAndFormatName($productoColumn): array { $solidario = Str::contains($productoColumn, '*'); @@ -91,9 +89,9 @@ private function parseAndFormatName($productoColumn): array { } return [ - 'solidario' => $solidario, - 'name' => trim($name), - 'caracteristicas' => $caracteristicas + $solidario, + trim($name), + $caracteristicas ]; }