forked from nathalie/pedi2
38 lines
1011 B
PHP
38 lines
1011 B
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();
|
||
|
$toInsert = [];
|
||
|
|
||
|
foreach($registros as $registro){
|
||
|
$toInsert[] = [
|
||
|
'nombre' => $registro['barrio'],
|
||
|
'region' => $registro['region'],
|
||
|
'telefono' => $registro['telefono'],
|
||
|
'correo' => $registro['correo'],
|
||
|
'referente_finanzas' => $registro['referente']
|
||
|
];
|
||
|
}
|
||
|
|
||
|
foreach (array_chunk($toInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||
|
{
|
||
|
DB::table('grupos_de_compra')->insert($chunk);
|
||
|
}
|
||
|
}
|
||
|
}
|