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
13 changes: 13 additions & 0 deletions src/Illuminate/Support/MessageBag.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,19 @@ public function hasAny($keys = [])
return false;
}

/**
* Determine if messages don't exist for all of the given keys.
*
* @param array|string|null $key
* @return bool
*/
public function missing($key)
{
$keys = is_array($key) ? $key : func_get_args();

return ! $this->hasAny($keys);
}

/**
* Get the first message from the message bag for a given key.
*
Expand Down
13 changes: 13 additions & 0 deletions tests/Support/SupportMessageBagTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,19 @@ public function testHasIndicatesExistence()
$this->assertFalse($container->has('bar'));
}

public function testMissingIndicatesNonExistence()
{
$container = new MessageBag;
$container->setFormat(':message');
$container->add('foo', 'bar');
$this->assertFalse($container->missing('foo'));
$this->assertFalse($container->missing(['foo', 'baz']));
$this->assertFalse($container->missing('foo', 'baz'));
$this->assertTrue($container->missing('baz'));
$this->assertTrue($container->missing(['baz', 'biz']));
$this->assertTrue($container->missing('baz', 'biz'));
}

public function testAddIf()
{
$container = new MessageBag;
Expand Down