original_string: public static function applyAppRoleMapByService($user, $serviceId)
      {
          $maps = AppRoleMap::whereServiceId($serviceId)->get();
  
          foreach ($maps as $map) {
              UserAppRole::whereUserId($user->id)->whereAppId($map->app_id)->delete();
              $userAppRoleData = [
                  'user_id' => $user->id,
                  'app_id'  => $map->app_id,
                  'role_id' => $map->role_id
              ];
  
              UserAppRole::create($userAppRoleData);
          }
      }
code: public static function applyAppRoleMapByService($user, $serviceId)
      {
          $maps = AppRoleMap::whereServiceId($serviceId)->get();
  
          foreach ($maps as $map) {
              UserAppRole::whereUserId($user->id)->whereAppId($map->app_id)->delete();
              $userAppRoleData = [
                  'user_id' => $user->id,
                  'app_id'  => $map->app_id,
                  'role_id' => $map->role_id
              ];
  
              UserAppRole::create($userAppRoleData);
          }
      }
code_tokens: public static function applyAppRoleMapByService ( $ user , $ serviceId ) { $ maps = AppRoleMap :: whereServiceId ( $ serviceId ) -> get ( ) ; foreach ( $ maps as $ map ) { UserAppRole :: whereUserId ( $ user -> id ) -> whereAppId ( $ map -> app_id ) -> delete ( ) ; $ userAppRoleData = [ 'user_id' => $ user -> id , 'app_id' => $ map -> app_id , 'role_id' => $ map -> role_id ] ; UserAppRole :: create ( $ userAppRoleData ) ; } }
docstring: Applies App to Role mapping to a user.
  
  @param User    $user
  @param integer $serviceId
docstring_tokens: Applies App to Role mapping to a user .