LMongo\Eloquent\Model::setAttribute PHP Method

setAttribute() public method

Set a given attribute on the model.
public setAttribute ( string $key, mixed $value ) : void
$key string
$value mixed
return void
    public function setAttribute($key, $value)
    {
        // First we will check for the presence of a mutator for the set operation
        // which simply lets the developers tweak the attribute as it is set on
        // the model, such as "json_encoding" an listing of data for storage.
        if ($this->hasSetMutator($key)) {
            $method = 'set' . studly_case($key) . 'Attribute';
            return $this->{$method}($value);
        } elseif (in_array($key, $this->getDates())) {
            if ($value) {
                $value = $this->fromDateTime($value);
            }
        }
        $this->attributes[$key] = $value;
    }

Usage Example

Example #1
0
 /**
  * Attach a model instance to the parent model.
  *
  * @param  \LMongo\Eloquent\Model  $model
  * @return \LMongo\Eloquent\Model
  */
 public function save(Model $model)
 {
     $model->setAttribute($this->foreignKey, new MongoID($this->parent->getKey()));
     return $model->save() ? $model : false;
 }
All Usage Examples Of LMongo\Eloquent\Model::setAttribute
Model