Skip to content

Commit

Permalink
Add session except method (#49520)
Browse files Browse the repository at this point in the history
  • Loading branch information
xurshudyan committed Dec 29, 2023
1 parent 9761bc9 commit 6de1fea
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Session/Store.php
Expand Up @@ -245,6 +245,17 @@ public function only(array $keys)
return Arr::only($this->attributes, $keys);
}

/**
* Get all the session data except for a specified array of items.
*
* @param array $keys
* @return array
*/
public function except(array $keys)
{
return Arr::except($this->attributes, $keys);
}

/**
* Checks if a key exists.
*
Expand Down
11 changes: 11 additions & 0 deletions tests/Session/SessionStoreTest.php
Expand Up @@ -329,6 +329,17 @@ public function testOnly()
$this->assertEquals(['qu' => 'ux'], $session->only(['qu']));
}

public function testExcept()
{
$session = $this->getSession();
$session->put('foo', 'bar');
$session->put('bar', 'baz');
$session->put('qu', 'ux');

$this->assertEquals(['foo' => 'bar', 'qu' => 'ux', 'bar' => 'baz'], $session->all());
$this->assertEquals(['bar' => 'baz', 'qu' => 'ux'], $session->except(['foo']));
}

public function testReplace()
{
$session = $this->getSession();
Expand Down

0 comments on commit 6de1fea

Please sign in to comment.