Last active
August 29, 2015 14:22
-
-
Save vinicius73/daac844171f491d2b450 to your computer and use it in GitHub Desktop.
UserTableSeeder.php
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use App\User; | |
use Illuminate\Database\Seeder; | |
class UserTableSeeder extends Seeder | |
{ | |
public function run() | |
{ | |
// Apaga toda a tabela de usuários | |
DB::table('users')->truncate(); | |
// Cria usuários admins (dados controlados) | |
$this->createAdmins(); | |
// Cria usuários demo (dados faker) | |
$this->createUsers(); | |
} | |
private function createAdmins() | |
{ | |
User::create([ | |
'email' => '[email protected]', | |
'name' => 'Vinicius Reis', | |
'password' => bcrypt('s&nh@') | |
]); | |
// Exibe uma informação no console durante o processo de seed | |
$this->command->info('User [email protected] created'); | |
User::create([ | |
'email' => '[email protected]', | |
'name' => 'João Bobo', | |
'password' => bcrypt('s&nh@') | |
]); | |
$this->command->info('User [email protected] created'); | |
} | |
private function createUsers() | |
{ | |
$max = rand(10, 30); | |
for($i=0; $i < $max; $i++): | |
$this->createUser($i); | |
endfor; | |
$this->command->info($max . ' demo users created'); | |
} | |
private function createUser($index) | |
{ | |
return User::create([ | |
'email' => 'email' . $index . '@mail.com', | |
'name' =>'User '. $index, | |
'password' => bcrypt('123456') | |
]); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment