pedi2/database/seeds/GrupoDeCompraSeeder.php

58 lines
1.6 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("asd"),
"is_admin" => 0,
'grupo_de_compra_id' => $key
];
$usersToInsert[] = [
'name' => $registro['barrio'] . "_admin",
'password' => Hash::make("asd"),
"is_admin" => 1,
'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);
}
}
}