Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[5.5] Add Request::keys method #20611

Merged
merged 1 commit into from
Aug 17, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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