Skip to content

Commit cd6e76f

Browse files
[8.x] fix Request offsetExists without routeResolver (#42754)
* fix Request offsetExists without routeResolver * simplify test * formatting Co-authored-by: Taylor Otwell <[email protected]>
1 parent 76faca7 commit cd6e76f

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

src/Illuminate/Http/Request.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -669,8 +669,10 @@ public function toArray()
669669
#[\ReturnTypeWillChange]
670670
public function offsetExists($offset)
671671
{
672+
$route = $this->route();
673+
672674
return Arr::has(
673-
$this->all() + $this->route()->parameters(),
675+
$this->all() + ($route ? $route->parameters() : []),
674676
$offset
675677
);
676678
}

tests/Http/HttpRequestTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -613,6 +613,17 @@ public function testArrayAccess()
613613
$this->assertSame('foo', $request['id']);
614614
}
615615

616+
public function testArrayAccessWithoutRouteResolver()
617+
{
618+
$request = Request::create('/', 'GET', ['name' => 'Taylor']);
619+
620+
$this->assertFalse(isset($request['non-existent']));
621+
$this->assertNull($request['non-existent']);
622+
623+
$this->assertTrue(isset($request['name']));
624+
$this->assertSame('Taylor', $request['name']);
625+
}
626+
616627
public function testAllMethod()
617628
{
618629
$request = Request::create('/', 'GET', ['name' => 'Taylor', 'age' => null]);

0 commit comments

Comments
 (0)