Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] add missing method to message bag class #48348

Merged
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 13 additions & 0 deletions src/Illuminate/Support/MessageBag.php
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
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