Skip to content

Commit 6de1fea

Browse files
authored
Add session except method (#49520)
1 parent 9761bc9 commit 6de1fea

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/Illuminate/Session/Store.php

+11
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,17 @@ public function only(array $keys)
245245
return Arr::only($this->attributes, $keys);
246246
}
247247

248+
/**
249+
* Get all the session data except for a specified array of items.
250+
*
251+
* @param array $keys
252+
* @return array
253+
*/
254+
public function except(array $keys)
255+
{
256+
return Arr::except($this->attributes, $keys);
257+
}
258+
248259
/**
249260
* Checks if a key exists.
250261
*

tests/Session/SessionStoreTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,17 @@ public function testOnly()
329329
$this->assertEquals(['qu' => 'ux'], $session->only(['qu']));
330330
}
331331

332+
public function testExcept()
333+
{
334+
$session = $this->getSession();
335+
$session->put('foo', 'bar');
336+
$session->put('bar', 'baz');
337+
$session->put('qu', 'ux');
338+
339+
$this->assertEquals(['foo' => 'bar', 'qu' => 'ux', 'bar' => 'baz'], $session->all());
340+
$this->assertEquals(['bar' => 'baz', 'qu' => 'ux'], $session->except(['foo']));
341+
}
342+
332343
public function testReplace()
333344
{
334345
$session = $this->getSession();

0 commit comments

Comments
 (0)