pedi2/database/seeds/GrupoDeCompraSeeder.php

49 lines
1.3 KiB
PHP
Raw Normal View History

<?php
use Illuminate\Database\Seeder;
use League\Csv\Reader;
class GrupoDeCompraSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$csv = Reader::createFromPath(resource_path('csv/barrios.csv'), 'r');
$csv->setDelimiter("|");
$csv->setEnclosure("'");
$csv->setHeaderOffset(0);
$registros = $csv->getRecords();
2022-01-08 02:53:00 -03:00
$gdcToInsert = [];
$usersToInsert = [];
foreach($registros as $registro){
2022-01-08 02:53:00 -03:00
$gdcToInsert[] = [
'nombre' => $registro['barrio'],
'region' => $registro['region'],
'telefono' => $registro['telefono'],
'correo' => $registro['correo'],
'referente_finanzas' => $registro['referente']
];
2022-01-08 02:53:00 -03:00
$usersToInsert[] = [
'name' => $registro['barrio'],
'password' => Hash::make($registro['barrio'])
];
}
2022-01-08 02:53:00 -03:00
foreach (array_chunk($gdcToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
{
DB::table('grupos_de_compra')->insert($chunk);
}
2022-01-08 02:53:00 -03:00
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
{
DB::table('users')->insert($chunk);
}
}
}