original_string: public function replaceFields($models)
  		{
  
  			// Loop through my fields
  			$url = $this->_pattern;
  			foreach ($this->_patternVariables as $var) {
  
  				// Look up
  				$varName = $var[0] == '#' ? substr($var, 1) : $var;
  				
  				// Was there a dot (.) in it, signifying a different model?
  				if (strstr($varName, '.')) {
  
  					// Split it!
  					list($modelName, $varName) = explode(".", $varName);
  					
  					// Loop through model instances to see if we have a match for the model name
  					$model = null;					
  					foreach ($models as $m) {
  						if (Str::removeNamespace(get_class($m)) == $modelName) {
  
  							// Use this model instead
  							$model = $m;
  							break;
  
  						}
  						
  					}
  					
  					// !Found?
  					if (is_null($model)) {
  						// Too bad...
  						throw new \Exception("You need to pass an Model instance of $modelName to generate a url for " . $this->_pattern, 1);
  						
  					}
  
  
  				} else {
  
  					// Use last model
  					$model = $models[count($models) - 1];
  
  				}
  
  
  				// Is there a slug var available?
  				$sluggedVarName = $varName . "Slug";
  				if ($model->hasAttribute($sluggedVarName)) {
  					$value = $model->$sluggedVarName;
  				} else {
  					$value = $model->$varName;
  				}
  
  				// Replace!
  				$url = str_replace('{' . $var . '}', strval($value), $url);
  
  			}
  			return $url;
  
  		}
code: public function replaceFields($models)
  		{
  
  			// Loop through my fields
  			$url = $this->_pattern;
  			foreach ($this->_patternVariables as $var) {
  
  				// Look up
  				$varName = $var[0] == '#' ? substr($var, 1) : $var;
  				
  				// Was there a dot (.) in it, signifying a different model?
  				if (strstr($varName, '.')) {
  
  					// Split it!
  					list($modelName, $varName) = explode(".", $varName);
  					
  					// Loop through model instances to see if we have a match for the model name
  					$model = null;					
  					foreach ($models as $m) {
  						if (Str::removeNamespace(get_class($m)) == $modelName) {
  
  							// Use this model instead
  							$model = $m;
  							break;
  
  						}
  						
  					}
  					
  					// !Found?
  					if (is_null($model)) {
  						// Too bad...
  						throw new \Exception("You need to pass an Model instance of $modelName to generate a url for " . $this->_pattern, 1);
  						
  					}
  
  
  				} else {
  
  					// Use last model
  					$model = $models[count($models) - 1];
  
  				}
  
  
  				// Is there a slug var available?
  				$sluggedVarName = $varName . "Slug";
  				if ($model->hasAttribute($sluggedVarName)) {
  					$value = $model->$sluggedVarName;
  				} else {
  					$value = $model->$varName;
  				}
  
  				// Replace!
  				$url = str_replace('{' . $var . '}', strval($value), $url);
  
  			}
  			return $url;
  
  		}
code_tokens: public function replaceFields ( $ models ) { // Loop through my fields $ url = $ this -> _pattern ; foreach ( $ this -> _patternVariables as $ var ) { // Look up $ varName = $ var [ 0 ] == '#' ? substr ( $ var , 1 ) : $ var ; // Was there a dot (.) in it, signifying a different model? if ( strstr ( $ varName , '.' ) ) { // Split it! list ( $ modelName , $ varName ) = explode ( "." , $ varName ) ; // Loop through model instances to see if we have a match for the model name $ model = null ; foreach ( $ models as $ m ) { if ( Str :: removeNamespace ( get_class ( $ m ) ) == $ modelName ) { // Use this model instead $ model = $ m ; break ; } } // !Found? if ( is_null ( $ model ) ) { // Too bad... throw new \ Exception ( "You need to pass an Model instance of $modelName to generate a url for " . $ this -> _pattern , 1 ) ; } } else { // Use last model $ model = $ models [ count ( $ models ) - 1 ] ; } // Is there a slug var available? $ sluggedVarName = $ varName . "Slug" ; if ( $ model -> hasAttribute ( $ sluggedVarName ) ) { $ value = $ model -> $ sluggedVarName ; } else { $ value = $ model -> $ varName ; } // Replace! $ url = str_replace ( '{' . $ var . '}' , strval ( $ value ) , $ url ) ; } return $ url ; }
docstring: Replace fields in the Route with values from the Model instances
  @param  \ChickenWire\Model $models Array of Model instances to use for values. The last in the array is assumed to be the primary Model to use for values.
  @return string        The uri with the fields replaced
docstring_tokens: Replace fields in the Route with values from the Model instances