当前位置: 首页>>代码示例>>PHP>>正文


PHP Group::query方法代码示例

本文整理汇总了PHP中app\models\Group::query方法的典型用法代码示例。如果您正苦于以下问题:PHP Group::query方法的具体用法?PHP Group::query怎么用?PHP Group::query使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Group的用法示例。


在下文中一共展示了Group::query方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: run

 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');
 }
开发者ID:linguisticteam,项目名称:laravel-boilerplate,代码行数:47,代码来源:UserGroupSeeder.php


注:本文中的app\models\Group::query方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。