34 lines
984 B
PHP
34 lines
984 B
PHP
<?php
|
|
|
|
use App\GrupoDeCompra;
|
|
use App\User;
|
|
use App\UserRole;
|
|
use Illuminate\Database\Seeder;
|
|
|
|
class UsuarioOllasSeeder extends Seeder
|
|
{
|
|
/**
|
|
* Run the database seeds.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function run()
|
|
{
|
|
$barrios = GrupoDeCompra::all();
|
|
$usersToInsert = [];
|
|
$ollas_id = UserRole::where('nombre', 'ollas')->first()->id;
|
|
$pedidos_id = UserRole::where('nombre', 'barrio')->first()->id;
|
|
|
|
foreach ($barrios as $barrio) {
|
|
$usersToInsert[] = DatabaseSeeder::addTimestamps([
|
|
'name' => $barrio->nombre . '_ollas',
|
|
'password' => User::where(['grupo_de_compra_id' => $barrio->id, 'role_id' => $pedidos_id])->first()->password,
|
|
'role_id' => $ollas_id,
|
|
'grupo_de_compra_id' => $barrio->id,
|
|
]);
|
|
}
|
|
|
|
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
|
User::insert($chunk);
|
|
}
|
|
}
|