Agregado seeder de usuarios de ollas
This commit is contained in:
parent
929191f173
commit
a74f89f684
2 changed files with 34 additions and 0 deletions
|
@ -24,5 +24,6 @@ class DatabaseSeeder extends Seeder
|
|||
$this->call(CanastaSeeder::class);
|
||||
$this->call(GrupoDeCompraSeeder::class);
|
||||
$this->call(UserSeeder::class);
|
||||
$this->call(UsuarioOllasSeeder::class);
|
||||
}
|
||||
}
|
||||
|
|
33
database/seeds/UsuarioOllasSeeder.php
Normal file
33
database/seeds/UsuarioOllasSeeder.php
Normal file
|
@ -0,0 +1,33 @@
|
|||
<?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,
|
||||
]);
|
||||
}
|
||||
|
||||
foreach (array_chunk($usersToInsert,DatabaseSeeder::CHUNK_SIZE) as $chunk)
|
||||
User::insert($chunk);
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue