diff --git a/src/SchemalessAttributes.php b/src/SchemalessAttributes.php index 5d2daaf..ac1f1e1 100644 --- a/src/SchemalessAttributes.php +++ b/src/SchemalessAttributes.php @@ -60,6 +60,20 @@ public function __set($name, $value) $this->set($name, $value); } + public function __isset($name) + { + $property = $this->get($name); + + return isset($property); + } + + public function __empty($name) + { + $property = $this->get($name); + + return empty($property); + } + /** * @see Collection::get() * diff --git a/tests/HasSchemalessAttributesTest.php b/tests/HasSchemalessAttributesTest.php index b1d8317..40e46fb 100644 --- a/tests/HasSchemalessAttributesTest.php +++ b/tests/HasSchemalessAttributesTest.php @@ -56,6 +56,26 @@ public function schemaless_attributes_will_get_saved_with_the_model() $this->assertEquals('value', $this->testModel->schemaless_attributes->name); } + /** @test */ + public function checking_existing_schemaless_attribute_is_empty_with_direct_access() + { + $this->testModel->schemaless_attributes->name = 'value'; + $this->testModel->save(); + + $this->assertFalse(empty($this->testModel->schemaless_attributes->name)); + $this->assertTrue(empty($this->testModel->schemaless_attributes->first_name)); + } + + /** @test */ + public function checking_existing_schemaless_attribute_is_empty_with_access_via_get() + { + $this->testModel->schemaless_attributes->name = 'value'; + $this->testModel->save(); + + $this->assertFalse(empty($this->testModel->schemaless_attributes->get('name'))); + $this->assertTrue(empty($this->testModel->schemaless_attributes->get('first_name'))); + } + /** @test */ public function it_can_handle_an_array() {