Skip to content

Commit 0068c43

Browse files
committed
Add MessageBag remove method
1 parent 24e0fb8 commit 0068c43

File tree

3 files changed

+28
-0
lines changed

3 files changed

+28
-0
lines changed

src/Illuminate/Contracts/Support/MessageBag.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,14 @@ public function keys();
2222
*/
2323
public function add($key, $message);
2424

25+
/**
26+
* Remove a message from the bag.
27+
*
28+
* @param string $key
29+
* @return $this
30+
*/
31+
public function remove($key);
32+
2533
/**
2634
* Merge a new array of messages into the bag.
2735
*

src/Illuminate/Support/MessageBag.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,19 @@ public function addIf($boolean, $key, $message)
7878
return $boolean ? $this->add($key, $message) : $this;
7979
}
8080

81+
/**
82+
* Remove a message from the message bag.
83+
*
84+
* @param string $key
85+
* @return $this
86+
*/
87+
public function remove($key)
88+
{
89+
unset($this->messages[$key]);
90+
91+
return $this;
92+
}
93+
8194
/**
8295
* Determine if a key and message combination already exists.
8396
*

tests/Support/SupportMessageBagTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,13 @@ public function testAddIf()
126126
$this->assertFalse($container->has('bar'));
127127
}
128128

129+
public function testRemove()
130+
{
131+
$container = new MessageBag(['foo' => 'bar']);
132+
$container->remove('foo');
133+
$this->assertFalse($container->has('foo'));
134+
}
135+
129136
public function testHasWithKeyNull()
130137
{
131138
$container = new MessageBag;

0 commit comments

Comments
 (0)