Skip to content

Commit

Permalink
add missing method to message bag class (#48348)
Browse files Browse the repository at this point in the history
  • Loading branch information
PH7-Jack committed Sep 11, 2023
1 parent 00894b8 commit 27ac244
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
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

0 comments on commit 27ac244

Please sign in to comment.