public function run() { $date = new \DateTime(); $people = $users = $userGroups = $groupList = $teamMembers = $members = $userAccounts = $teams = $teamLanguages = $teamLanguageSupports = []; //Reading the CSV file to get a list of groups $groupCSV = \League\Csv\Reader::createFromPath($this->baseDir . 'users_groups_permissions.tsv', 'r'); $groupCSV->setDelimiter(chr(9)); $groupCSVData = $groupCSV->fetchAssoc(); foreach ($groupCSVData as $data) { if ($data['group_name'] != 'users' && $data['group_name'] != 'administrators') { Models\Group::create(['group_name' => $data['group_name']]); } } //Getting the groups we just created from the db and an associative array $dbGroups = Models\Group::query()->pluck('group_id', 'group_name')->toArray(); //Every user gets a password of test, for testing purposes $userPassword = bcrypt('test'); $personDBColumns = $this->getFillableDBModelFields('\\App\\Models\\Person'); //Reading the users CSV file $userCSV = \League\Csv\Reader::createFromPath($this->baseDir . 'users.tsv', 'r'); $userCSV->setDelimiter(chr(9)); $userCSVData = $userCSV->fetchAssoc(); foreach ($userCSVData as $key => $data) { //We use every column in the CSV whose name matches with a field in the people table $people[$key] = $this->fillArrayFromModel($data, array_flip($personDBColumns)); $people[$key]['person_birthdate'] = strtotime($people[$key]['person_birthdate']); $users[$key] = ['email' => $data['email'], 'name' => $data['name'], 'password' => $userPassword, 'activated' => true, 'last_login' => $date, 'created_at' => $date]; $users[$key]['person_id'] = $key + 1; //Adding users to their groups if (!empty($data['groups'])) { $groups = explode(',', $data['groups']); if (!empty($groups)) { foreach ($groups as $group) { if (isset($dbGroups[$group]) && $group != 'users') { $userGroups[] = ['user_id' => $key + 1, 'group_id' => $dbGroups[$group]]; } } } } //Everyone gets to be a part of the users group, yay! $userGroups[] = ['user_id' => $key + 1, 'group_id' => Models\Group::users]; } DB::table('people')->insert($people); DB::table('users')->insert($users); DB::table('user_groups')->insert($userGroups); $this->command->info('Users & Groups seeded'); }