From 6de1fead25697b8cf028e18d237a4a729fd5be2b Mon Sep 17 00:00:00 2001 From: Volodya Kurshudyan <70023120+xurshudyan@users.noreply.github.com> Date: Sat, 30 Dec 2023 01:53:12 +0400 Subject: [PATCH] Add session except method (#49520) --- src/Illuminate/Session/Store.php | 11 +++++++++++ tests/Session/SessionStoreTest.php | 11 +++++++++++ 2 files changed, 22 insertions(+) diff --git a/src/Illuminate/Session/Store.php b/src/Illuminate/Session/Store.php index 10184dee58d..fb9e2c4fd5d 100755 --- a/src/Illuminate/Session/Store.php +++ b/src/Illuminate/Session/Store.php @@ -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. * diff --git a/tests/Session/SessionStoreTest.php b/tests/Session/SessionStoreTest.php index d9ef8d3ec64..bfb064048e5 100644 --- a/tests/Session/SessionStoreTest.php +++ b/tests/Session/SessionStoreTest.php @@ -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();