46 lines
1.3 KiB
PHP
46 lines
1.3 KiB
PHP
<?php
|
|
|
|
use App\Helpers\CsvHelper;
|
|
use App\GrupoDeCompra;
|
|
use App\User;
|
|
use App\UserRole;
|
|
use Illuminate\Database\Seeder;
|
|
use Illuminate\Support\Facades\Hash;
|
|
|
|
class GrupoDeCompraSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$registros = CsvHelper::getRecords('csv/barrios.csv');
|
|
$gdcToInsert = [];
|
|
$usersToInsert = [];
|
|
$roles = UserRole::where('nombre', 'barrio')->orWhere('nombre', 'barrio_admin')->get();
|
|
|
|
foreach($registros as $key => $registro){
|
|
$gdcToInsert[] = [
|
|
'nombre' => $registro['barrio'],
|
|
'region' => $registro['region'],
|
|
];
|
|
|
|
foreach($roles as $role) {
|
|
$usersToInsert[] = [
|
|
'name' => $registro['barrio'],
|
|
'password' => Hash::make("123"),
|
|
'role_id' => $role->id,
|
|
'grupo_de_compra_id' => $key,
|
|
];
|
|
}
|
|
}
|
|
|
|
foreach (array_chunk($gdcToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
|
GrupoDeCompra::insert($chunk);
|
|
|
|
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
|
User::insert($chunk);
|
|
}
|
|
}
|