Example #1
0
 /**
  * @test
  */
 public function it_instantiates_as_eloquent_by_default()
 {
     $emptyModel = new Attribute();
     $arrayModel = new Attribute([]);
     $this->assertEquals([], $emptyModel->getAttributes());
     $this->assertEquals([], $arrayModel->getAttributes());
 }
Example #2
0
 /**
  * Update existing attribute.
  *
  * @param  \Sofa\Eloquence\Metable\Attribute|string $key
  * @param  mixed  $value
  * @return $this
  */
 protected function update($key, $value = null)
 {
     if ($key instanceof Attribute) {
         $value = $key->getValue();
         $key = $key->getMetaKey();
     }
     $this->get($key)->setValue($value);
     return $this;
 }
Example #3
0
 /**
  * Set attribute.
  *
  * @param \Sofa\Eloquence\Metable\Attribute $attribute
  */
 protected function setInstance(Attribute $attribute)
 {
     if ($this->has($attribute->getMetaKey())) {
         $this->update($attribute);
     } else {
         $this->items[$attribute->getMetaKey()] = $attribute;
     }
     return $this;
 }