protected function buildUniqueExclusionRules(array $rules = array()) {
      
        if (!count($rules))
          $rules = static::$rules;

        foreach ($rules as $field => &$ruleset) {
            // If $ruleset is a pipe-separated string, switch it to array
            $ruleset = (is_string($ruleset))? explode('|', $ruleset) : $ruleset;

            foreach ($ruleset as &$rule) {
              if (strpos($rule, 'unique') === 0) {
                $params = explode(',', $rule);

                $uniqueRules = array();
                
                // Append table name if needed
                $table = explode(':', $params[0]);
                if (count($table) == 1)
                  $uniqueRules[1] = $this->table;
                else
                  $uniqueRules[1] = $table[1];
               
                // Append field name if needed
                if (count($params) == 1)
                  $uniqueRules[2] = $field;
                else
                  $uniqueRules[2] = $params[1];

                if (isset($this->primaryKey)) {
                  $uniqueRules[3] = $this->{$this->primaryKey};
                  $uniqueRules[4] = $this->primaryKey;
                }
                else {
                  $uniqueRules[3] = $this->id;
                }
       
                $rule = 'unique:' . implode(',', $uniqueRules);  
              } // end if strpos unique
              
            } // end foreach ruleset
        }
        
        return $rules;
    }
protected function buildUniqueExclusionRules(array $rules = array()) {
      
        if (!count($rules))
          $rules = static::$rules;

        foreach ($rules as $field => &$ruleset) {
            // If $ruleset is a pipe-separated string, switch it to array
            $ruleset = (is_string($ruleset))? explode('|', $ruleset) : $ruleset;

            foreach ($ruleset as &$rule) {
              if (strpos($rule, 'unique') === 0) {
                $params = explode(',', $rule);

                $uniqueRules = array();
                
                // Append table name if needed
                $table = explode(':', $params[0]);
                if (count($table) == 1)
                  $uniqueRules[1] = $this->table;
                else
                  $uniqueRules[1] = $table[1];
               
                // Append field name if needed
                if (count($params) == 1)
                  $uniqueRules[2] = $field;
                else
                  $uniqueRules[2] = $params[1];

                if (isset($this->primaryKey)) {
                  $uniqueRules[3] = $this->{$this->primaryKey};
                  $uniqueRules[4] = $this->primaryKey;
                }
                else {
                  $uniqueRules[3] = $this->id;
                }
       
                $rule = 'unique:' . implode(',', $uniqueRules);  
              } // end if strpos unique
              
            } // end foreach ruleset
        }
        
        return $rules;
    }
protected function buildUniqueExclusionRules ( array $ rules = array ( ) ) { if ( ! count ( $ rules ) ) $ rules = static :: $ rules ; foreach ( $ rules as $ field => & $ ruleset ) { // If $ruleset is a pipe-separated string, switch it to array $ ruleset = ( is_string ( $ ruleset ) ) ? explode ( '|' , $ ruleset ) : $ ruleset ; foreach ( $ ruleset as & $ rule ) { if ( strpos ( $ rule , 'unique' ) === 0 ) { $ params = explode ( ',' , $ rule ) ; $ uniqueRules = array ( ) ; // Append table name if needed $ table = explode ( ':' , $ params [ 0 ] ) ; if ( count ( $ table ) == 1 ) $ uniqueRules [ 1 ] = $ this -> table ; else $ uniqueRules [ 1 ] = $ table [ 1 ] ; // Append field name if needed if ( count ( $ params ) == 1 ) $ uniqueRules [ 2 ] = $ field ; else $ uniqueRules [ 2 ] = $ params [ 1 ] ; if ( isset ( $ this -> primaryKey ) ) { $ uniqueRules [ 3 ] = $ this -> { $ this -> primaryKey } ; $ uniqueRules [ 4 ] = $ this -> primaryKey ; } else { $ uniqueRules [ 3 ] = $ this -> id ; } $ rule = 'unique:' . implode ( ',' , $ uniqueRules ) ; } // end if strpos unique } // end foreach ruleset } return $ rules ; }
When given an ID and a FlyPHP validation rules array, this function
appends the ID to the 'unique' rules given. The resulting array can
then be fed to a SmartModel save so that unchanged values
don't flag a validation issue. Rules can be in either strings
with pipes or arrays, but the returned rules are in arrays.

@param int   $id
@param array $rules

@return array Rules with exclusions applied
When given an ID and a FlyPHP validation rules array this function appends the ID to the unique rules given . The resulting array can then be fed to a SmartModel save so that unchanged values don t flag a validation issue . Rules can be in either strings with pipes or arrays but the returned rules are in arrays .