/**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     User::truncate();
     \DB::table('user_meta')->truncate();
     \DB::table('role_user')->truncate();
     $roles = Role::pluck('id')->all();
     $maxRolesToAttach = count($roles) > 4 ? 4 : count($roles);
     $faker = \Faker\Factory::create();
     $totalUsers = 5;
     $user = User::create(['email' => '*****@*****.**', 'password' => 'password', 'name' => 'admin', 'locale' => 'ru']);
     $user->roles()->sync($roles);
     $user = User::create(['email' => '*****@*****.**', 'password' => 'password', 'name' => 'admin_en', 'locale' => 'en']);
     $user->roles()->sync([1, 2, 3]);
     $usedEmails = $usedUsernames = [];
     for ($i = 0; $i < $totalUsers; $i++) {
         do {
             $email = strtolower($faker->email);
         } while (in_array($email, $usedEmails));
         $usedEmails[] = $email;
         do {
             $username = strtolower($faker->userName);
         } while (in_array($username, $usedUsernames));
         $usedUsernames[] = $username;
         $user = User::create(['email' => $email, 'password' => 'password', 'name' => $username, 'locale' => $faker->randomElement(['ru', 'en'])]);
         $user->roles()->attach($faker->randomElements($roles, rand(1, $maxRolesToAttach)));
     }
 }
 /**
  * Create a new user instance after a valid registration.
  *
  * @param  array $data
  * @return User
  */
 public function create(array $data)
 {
     $user = User::create(array_only($data, ['username', 'password', 'email', 'locale']));
     if (isset($data['user_roles'])) {
         $roles = $data['user_roles'];
         if (!is_array($roles)) {
             $roles = explode(',', $roles);
         }
         $user->roles()->attach($roles);
     }
     return $user;
 }
 /**
  * Создание администратора.
  */
 public function createAdmin(array $config)
 {
     // Delete seeder admin users
     User::where('email', 'like', '*****@*****.**')->delete();
     $user = User::create(['email' => array_get($config, 'email'), 'password' => array_get($config, 'password'), 'username' => array_get($config, 'username'), 'locale' => array_get($config, 'locale', 'en')]);
     $user->roles()->sync([1, 2, 3]);
 }