Skip to content

Commit

Permalink
allows array or multiple params for hasAny helper (#22952)
Browse files Browse the repository at this point in the history
  • Loading branch information
themsaid authored and taylorotwell committed Jan 29, 2018
1 parent 5923416 commit d93d0fa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
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

0 comments on commit d93d0fa

Please sign in to comment.