Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions src/Illuminate/Support/Fluent.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down
19 changes: 19 additions & 0 deletions tests/Support/SupportFluentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading