Skip to content

Commit 27ac244

Browse files
authored
add missing method to message bag class (#48348)
1 parent 00894b8 commit 27ac244

File tree

2 files changed

+26
-0
lines changed

2 files changed

+26
-0
lines changed

src/Illuminate/Support/MessageBag.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,19 @@ public function hasAny($keys = [])
159159
return false;
160160
}
161161

162+
/**
163+
* Determine if messages don't exist for all of the given keys.
164+
*
165+
* @param array|string|null $key
166+
* @return bool
167+
*/
168+
public function missing($key)
169+
{
170+
$keys = is_array($key) ? $key : func_get_args();
171+
172+
return ! $this->hasAny($keys);
173+
}
174+
162175
/**
163176
* Get the first message from the message bag for a given key.
164177
*

tests/Support/SupportMessageBagTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,19 @@ public function testHasIndicatesExistence()
115115
$this->assertFalse($container->has('bar'));
116116
}
117117

118+
public function testMissingIndicatesNonExistence()
119+
{
120+
$container = new MessageBag;
121+
$container->setFormat(':message');
122+
$container->add('foo', 'bar');
123+
$this->assertFalse($container->missing('foo'));
124+
$this->assertFalse($container->missing(['foo', 'baz']));
125+
$this->assertFalse($container->missing('foo', 'baz'));
126+
$this->assertTrue($container->missing('baz'));
127+
$this->assertTrue($container->missing(['baz', 'biz']));
128+
$this->assertTrue($container->missing('baz', 'biz'));
129+
}
130+
118131
public function testAddIf()
119132
{
120133
$container = new MessageBag;

0 commit comments

Comments
 (0)