コード例 #1
0
 public function run()
 {
     $this->command->info('Seeding role to user associations.');
     $userRoles = [['user_id' => 1, 'role_id' => Role::ID_ADMIN]];
     foreach (Board::get() as $board) {
         $userRoles[] = ['user_id' => $board->operated_by, 'role_id' => $board->getOwnerRole()->role_id];
     }
     foreach ($userRoles as $userRole) {
         UserRole::firstOrCreate($userRole);
     }
 }
コード例 #2
0
ファイル: RoleSeeder.php プロジェクト: LulzNews/infinity-next
 public function run()
 {
     $this->command->info('Seeding role to user associations.');
     $userRoles = [];
     $admins = User::whereIn('user_id', explode(",", env('APP_ROOT_USERS', "1")))->get();
     foreach ($admins as $admin) {
         $userRoles[] = ['user_id' => $admin->user_id, 'role_id' => Role::ID_ADMIN];
     }
     Board::with('operator', 'roles')->has('operator')->chunk(50, function ($boards) use(&$userRoles) {
         foreach ($boards as $board) {
             $boardRole = $board->getOwnerRole();
             // Drops all board owner user roles where the user isn't a board operator.
             $removed = UserRole::whereHas('role', function ($query) use($boardRole) {
                 $query->where('role_id', $boardRole->role_id);
             })->whereHas('user', function ($query) use($board) {
                 $query->where('user_id', "<>", $board->operated_by);
             })->forceDelete();
             if ($removed > 0) {
                 $this->command->line("\tRemoved {$removed} pretenders from /{$board->board_uri}/.");
             }
             $userRoles[] = ['user_id' => $board->operated_by, 'role_id' => $boardRole->role_id];
         }
     });
     foreach ($userRoles as $userRole) {
         UserRole::firstOrCreate($userRole);
     }
 }
コード例 #3
0
 public function run()
 {
     $this->command->info('Seeding role to user associations.');
     $userRoles = [];
     $admins = User::whereIn('user_id', explode(",", env('APP_ROOT_USERS', "1")))->get();
     foreach ($admins as $admin) {
         $userRoles[] = ['user_id' => $admin->user_id, 'role_id' => Role::ID_ADMIN];
     }
     foreach (Board::get() as $board) {
         $ownerRole = $board->getOwnerRole();
         if ($ownerRole) {
             $userRoles[] = ['user_id' => $board->operated_by, 'role_id' => $ownerRole->role_id];
         } else {
             $this->command->line("\t/{$board->board_uri}/ has no owner role.");
         }
     }
     foreach ($userRoles as $userRole) {
         UserRole::firstOrCreate($userRole);
     }
 }