From 95a9a404d2a0bc4b8faf2a9f3020a527ba997ce2 Mon Sep 17 00:00:00 2001 From: ale Date: Sat, 21 Dec 2024 15:08:35 -0300 Subject: [PATCH] Manejo de archivos movido a helper y limpieza --- app/Helpers/CanastaHelper.php | 8 ++++++++ app/Http/Controllers/ComprasController.php | 5 +---- database/seeds/CanastaSeeder.php | 2 -- 3 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Helpers/CanastaHelper.php b/app/Helpers/CanastaHelper.php index 1433781..c0b933b 100644 --- a/app/Helpers/CanastaHelper.php +++ b/app/Helpers/CanastaHelper.php @@ -14,6 +14,14 @@ class CanastaHelper const FILA_HEADER = "Tipo"; const ULTIMA_FILA = "TOTAL"; + public static function guardarCanasta($data, $path): string + { + $nombre = $data->getClientOriginalName(); + + $data->move(resource_path($path), $nombre); + return $nombre; + } + public static function cargarCanasta($archivo) { $csv = Reader::createFromPath(resource_path($archivo), 'r'); $csv->setDelimiter("|"); diff --git a/app/Http/Controllers/ComprasController.php b/app/Http/Controllers/ComprasController.php index d30db9d..a2e01f6 100644 --- a/app/Http/Controllers/ComprasController.php +++ b/app/Http/Controllers/ComprasController.php @@ -44,10 +44,7 @@ class ComprasController 'data' => 'required|file|mimes:csv,txt|max:2048', ]); - $data = $request->file('data'); - $nombre = $data->getClientOriginalName(); - - $data->move(resource_path(self::CANASTAS_PATH), $nombre); + $nombre = CanastaHelper::guardarCanasta($request->file('data'), self::CANASTAS_PATH); CanastaHelper::cargarCanasta(self::CANASTAS_PATH . $nombre); return response()->json([ diff --git a/database/seeds/CanastaSeeder.php b/database/seeds/CanastaSeeder.php index 90775b0..167fa8f 100644 --- a/database/seeds/CanastaSeeder.php +++ b/database/seeds/CanastaSeeder.php @@ -2,8 +2,6 @@ use App\Helpers\CanastaHelper; use Illuminate\Database\Seeder; -use League\Csv\Reader; -use App\Proveedor; class CanastaSeeder extends Seeder {