From 07b17bfe0a32de0497d7a15c54d2c50349ccd2ee Mon Sep 17 00:00:00 2001 From: Christian Worreschk Date: Tue, 22 Jul 2025 09:39:13 +0200 Subject: [PATCH] Add 'isEmpty' and 'isNotEmpty' to Fluent --- src/Illuminate/Support/Fluent.php | 20 ++++++++++++++++++++ tests/Support/SupportFluentTest.php | 19 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/src/Illuminate/Support/Fluent.php b/src/Illuminate/Support/Fluent.php index 3c2273c4c71d..f4459a57d61e 100755 --- a/src/Illuminate/Support/Fluent.php +++ b/src/Illuminate/Support/Fluent.php @@ -203,6 +203,26 @@ public function toJson($options = 0) return json_encode($this->jsonSerialize(), $options); } + /** + * Determine if the fluent instance is empty. + * + * @return bool + */ + public function isEmpty(): bool + { + return empty($this->attributes); + } + + /** + * Determine if the fluent instance is not empty. + * + * @return bool + */ + public function isNotEmpty(): bool + { + return ! $this->isEmpty(); + } + /** * Determine if the given offset exists. * diff --git a/tests/Support/SupportFluentTest.php b/tests/Support/SupportFluentTest.php index a81fd694e0b8..fe0edb1aedb7 100755 --- a/tests/Support/SupportFluentTest.php +++ b/tests/Support/SupportFluentTest.php @@ -471,6 +471,25 @@ public function testFluentIsIterable() 'role' => 'admin', ], $result); } + + public function testFluentIsEmpty() + { + $fluent = new Fluent; + + $this->assertTrue($fluent->isEmpty()); + $this->assertFalse($fluent->isNotEmpty()); + } + + public function testFluentIsNotEmpty() + { + $fluent = new Fluent([ + 'name' => 'Taylor', + 'role' => 'admin', + ]); + + $this->assertTrue($fluent->isNotEmpty()); + $this->assertFalse($fluent->isEmpty()); + } } class FluentArrayIteratorStub implements IteratorAggregate