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.6] Allows array or multiple params for hasAny helper #22952

Merged
merged 1 commit into from
Jan 29, 2018
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
6 changes: 4 additions & 2 deletions src/Illuminate/Http/Concerns/InteractsWithInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ public function has($key)
/**
* Determine if the request contains any of the given inputs.
*
* @param dynamic $key
* @param string|array $key
* @return bool
*/
public function hasAny(...$keys)
public function hasAny($keys)
{
$keys = is_array($keys) ? $keys : func_get_args();

$input = $this->all();

foreach ($keys as $key) {
Expand Down
3 changes: 3 additions & 0 deletions tests/Http/HttpRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -262,15 +262,18 @@ public function testHasAnyMethod()
$this->assertTrue($request->hasAny('city'));
$this->assertFalse($request->hasAny('foo'));
$this->assertTrue($request->hasAny('name', 'email'));
$this->assertTrue($request->hasAny(['name', 'email']));

$request = Request::create('/', 'GET', ['name' => 'Taylor', 'email' => 'foo']);
$this->assertTrue($request->hasAny('name', 'email'));
$this->assertFalse($request->hasAny('surname', 'password'));
$this->assertFalse($request->hasAny(['surname', 'password']));

$request = Request::create('/', 'GET', ['foo' => ['bar' => null, 'baz' => '']]);
$this->assertTrue($request->hasAny('foo.bar'));
$this->assertTrue($request->hasAny('foo.baz'));
$this->assertFalse($request->hasAny('foo.bax'));
$this->assertTrue($request->hasAny(['foo.bax', 'foo.baz']));
}

public function testFilledMethod()
Expand Down