Skip to content

Commit 0485e3a

Browse files
[9.x] Handle undefined array key error (#42606)
* Handle undefined array key error * Update Route.php Co-authored-by: Taylor Otwell <[email protected]>
1 parent 20faf9f commit 0485e3a

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

src/Illuminate/Routing/Route.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,13 @@ public function signatureParameters($conditions = [])
536536
public function bindingFieldFor($parameter)
537537
{
538538
if (is_int($parameter)) {
539-
$parameter = $this->parameterNames()[$parameter];
539+
$parameters = $this->parameterNames();
540+
541+
if (! isset($parameters[$parameter])) {
542+
return null;
543+
}
544+
545+
$parameter = $parameters[$parameter];
540546
}
541547

542548
return $this->bindingFields[$parameter] ?? null;

tests/Routing/RoutingUrlGeneratorTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,24 @@ public function testRoutableInterfaceRoutingWithCustomBindingField()
373373
$this->assertSame('/foo/test-slug', $url->route('routable', [$model], false));
374374
}
375375

376+
public function testRoutableInterfaceRoutingAsQueryString()
377+
{
378+
$url = new UrlGenerator(
379+
$routes = new RouteCollection,
380+
Request::create('http://www.foo.com/')
381+
);
382+
383+
$route = new Route(['GET'], 'foo', ['as' => 'query-string']);
384+
$routes->add($route);
385+
386+
$model = new RoutableInterfaceStub;
387+
$model->key = 'routable';
388+
389+
$this->assertSame('/foo?routable', $url->route('query-string', $model, false));
390+
$this->assertSame('/foo?routable', $url->route('query-string', [$model], false));
391+
$this->assertSame('/foo?foo=routable', $url->route('query-string', ['foo' => $model], false));
392+
}
393+
376394
public function testRoutableInterfaceRoutingWithSeparateBindingFieldOnlyForSecondParameter()
377395
{
378396
$url = new UrlGenerator(

0 commit comments

Comments
 (0)