Skip to content

Commit

Permalink
Add Request::keys method (#20611)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntzm authored and taylorotwell committed Aug 17, 2017
1 parent 129e899 commit 1e2dbe0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,16 @@ public function all($keys = null)
return $results;
}

/**
* Get the keys for all input and files for the request.
*
* @return array
*/
public function keys()
{
return array_merge(array_keys($this->input()), $this->files->keys());
}

/**
* Retrieve an input item from the request.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,27 @@ public function testAllMethod()
$this->assertEquals(['developer' => ['name' => 'Taylor', 'age' => null]], $request->all());
}

public function testKeysMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]);
$this->assertEquals(['name', 'age'], $request->keys());

$files = [
'foo' => [
'size' => 500,
'name' => 'foo.jpg',
'tmp_name' => __FILE__,
'type' => 'blah',
'error' => null,
],
];
$request = Request::create('/', 'GET', [], [], $files);
$this->assertEquals(['foo'], $request->keys());

$request = Request::create('/', 'GET', ['name' => 'Taylor'], [], $files);
$this->assertEquals(['name', 'foo'], $request->keys());
}

public function testOnlyMethod()
{
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]);
Expand Down

0 comments on commit 1e2dbe0

Please sign in to comment.