55 lines
1.6 KiB
PHP
55 lines
1.6 KiB
PHP
<?php
|
|
|
|
use App\Helpers\CsvHelper as CsvHelperAlias;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\DB;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class GrupoDeCompraSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$registros = CsvHelperAlias::getRecords('csv/barrios.csv');
|
|
$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("123"),
|
|
"is_admin" => 0,
|
|
'grupo_de_compra_id' => $key
|
|
];
|
|
|
|
$usersToInsert[] = [
|
|
'name' => $registro['barrio'] . "_admin",
|
|
'password' => Hash::make("123"),
|
|
"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);
|
|
}
|
|
}
|
|
}
|