diff --git a/src/Fields/Value.php b/src/Fields/Value.php index b7823890f6..b4d2c12ba0 100644 --- a/src/Fields/Value.php +++ b/src/Fields/Value.php @@ -224,6 +224,11 @@ public function __call(string $name, array $arguments) return $this->value()->{$name}(...$arguments); } + public function __isset($key) + { + return isset($this->value()?->{$key}); + } + public function __get($key) { return $this->value()?->{$key} ?? null; diff --git a/tests/Fields/ValueTest.php b/tests/Fields/ValueTest.php index 6ec9af7566..49b929bca1 100644 --- a/tests/Fields/ValueTest.php +++ b/tests/Fields/ValueTest.php @@ -322,6 +322,18 @@ public function it_can_iterate_over_values() ], $arr); } + #[Test] + public function it_can_check_emptiness_on_properties() + { + $val = new Value((object) [ + 'a' => 'alfa', + 'b' => '', + ]); + + $this->assertNotTrue(empty($val->a)); + $this->assertTrue(empty($val->b)); + } + #[Test] public function it_can_proxy_methods_to_value() {