Pantheon\Terminus\Collections\TerminusCollection::add PHP Method

add() public method

Adds a model to this collection
public add ( object $model_data, array $options = [] ) : TerminusModel
$model_data object Data to feed into attributes of new model
$options array Data to make properties of the new model
return TerminusModel
    public function add($model_data, array $options = [])
    {
        $options = array_merge(['id' => $model_data->id, 'collection' => $this], $options);
        $model = $this->getContainer()->get($this->collected_class, [$model_data, $options]);
        $this->models[$model_data->id] = $model;
        return $model;
    }

Usage Example

 /**
  * Adds a model to this collection
  *
  * @param object $model_data Data to feed into attributes of new model
  * @param array $options Data to make properties of the new model
  * @return TerminusModel
  */
 public function add($model_data, array $options = [])
 {
     $model = parent::add($model_data, $options);
     $model->setDataStore($this->getDataStore());
     return $model;
 }