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 {