forked from nathalie/pedi2
50 lines
1.4 KiB
PHP
50 lines
1.4 KiB
PHP
<?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();
|
|
$gdcToInsert = [];
|
|
$usersToInsert = [];
|
|
|
|
foreach($registros as $key => $registro){
|
|
$gdcToInsert[] = [
|
|
'nombre' => $registro['barrio'],
|
|
'region' => $registro['region'],
|
|
'telefono' => $registro['telefono'],
|
|
'correo' => $registro['correo'],
|
|
'referente_finanzas' => $registro['referente']
|
|
];
|
|
|
|
$usersToInsert[] = [
|
|
'name' => $registro['barrio'],
|
|
'password' => Hash::make($registro['barrio']),
|
|
'grupo_de_compra_id' => $key
|
|
];
|
|
}
|
|
|
|
foreach (array_chunk($gdcToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
|
{
|
|
DB::table('grupos_de_compra')->insert($chunk);
|
|
}
|
|
|
|
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
|
{
|
|
DB::table('users')->insert($chunk);
|
|
}
|
|
}
|
|
}
|