From cf8065ccd0bd3aec5d19483aec85f3ecd2936407 Mon Sep 17 00:00:00 2001 From: Mohamed Said Date: Sat, 6 Aug 2016 16:08:02 +0200 Subject: [PATCH] support dot notation in Request::exists() to fix #14643 (#14660) --- src/Illuminate/Http/Request.php | 2 +- tests/Http/HttpRequestTest.php | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index fcf0bf4532b9..555dddb75a95 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -273,7 +273,7 @@ public function exists($key) $input = $this->all(); foreach ($keys as $value) { - if (! array_key_exists($value, $input)) { + if (! Arr::has($input, $value)) { return false; } } diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index cea56ec146c7..333c459c5ac3 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -204,6 +204,10 @@ public function testExistsMethod() $request = Request::create('/', 'GET', ['foo' => '', 'bar' => null]); $this->assertTrue($request->exists('foo')); $this->assertTrue($request->exists('bar')); + + $request = Request::create('/', 'GET', ['foo' => ['bar' => null, 'baz' => '']]); + $this->assertTrue($request->exists('foo.bar')); + $this->assertTrue($request->exists('foo.baz')); } public function testHasMethod() @@ -220,6 +224,9 @@ public function testHasMethod() //test arrays within query string $request = Request::create('/', 'GET', ['foo' => ['bar', 'baz']]); $this->assertTrue($request->has('foo')); + + $request = Request::create('/', 'GET', ['foo' => ['bar' => 'baz']]); + $this->assertTrue($request->has('foo.bar')); } public function testInputMethod()