From cd6e76fe864161af7307be7abb6d4d18cbe064ca Mon Sep 17 00:00:00 2001 From: Daniel Esteve Date: Fri, 10 Jun 2022 20:50:29 +0200 Subject: [PATCH] [8.x] fix `Request` offsetExists without routeResolver (#42754) * fix Request offsetExists without routeResolver * simplify test * formatting Co-authored-by: Taylor Otwell --- src/Illuminate/Http/Request.php | 4 +++- tests/Http/HttpRequestTest.php | 11 +++++++++++ 2 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Http/Request.php b/src/Illuminate/Http/Request.php index 06bc955633fb..79175ac4476e 100644 --- a/src/Illuminate/Http/Request.php +++ b/src/Illuminate/Http/Request.php @@ -669,8 +669,10 @@ public function toArray() #[\ReturnTypeWillChange] public function offsetExists($offset) { + $route = $this->route(); + return Arr::has( - $this->all() + $this->route()->parameters(), + $this->all() + ($route ? $route->parameters() : []), $offset ); } diff --git a/tests/Http/HttpRequestTest.php b/tests/Http/HttpRequestTest.php index 6fb0c9b54d36..e401ce960cd0 100644 --- a/tests/Http/HttpRequestTest.php +++ b/tests/Http/HttpRequestTest.php @@ -613,6 +613,17 @@ public function testArrayAccess() $this->assertSame('foo', $request['id']); } + public function testArrayAccessWithoutRouteResolver() + { + $request = Request::create('/', 'GET', ['name' => 'Taylor']); + + $this->assertFalse(isset($request['non-existent'])); + $this->assertNull($request['non-existent']); + + $this->assertTrue(isset($request['name'])); + $this->assertSame('Taylor', $request['name']); + } + public function testAllMethod() { $request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]);