Skip to content

Commit

Permalink
Merge pull request #29107 from nicoeg/session-only-method
Browse files Browse the repository at this point in the history
[5.8] Add only method to Session
  • Loading branch information
taylorotwell authored Jul 8, 2019
2 parents 0f36cd1 + 0fe3467 commit ec4178b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Illuminate/Session/Store.php
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,17 @@ public function all()
return $this->attributes;
}

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

/**
* Checks if a key exists.
*
Expand Down
9 changes: 9 additions & 0 deletions tests/Session/SessionStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,15 @@ public function testReflashWithNow()
$this->assertFalse(array_search('foo', $session->get('_flash.old')));
}

public function testOnly()
{
$session = $this->getSession();
$session->put('foo', 'bar');
$session->put('qu', 'ux');
$this->assertEquals(['foo' => 'bar', 'qu' => 'ux'], $session->all());
$this->assertEquals(['qu' => 'ux'], $session->only(['qu']));
}

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

0 comments on commit ec4178b

Please sign in to comment.