Repository: laravel/framework (php)

Issue:
v9.15 has breaking change in route() helper: Unidentified array key 0
<!-- DO NOT THROW THIS AWAY -->
<!-- Fill out the FULL versions with patch versions -->

- Laravel Version: 9.15.0
- PHP Version: 8.0.18
- Database Driver & Version: MySQL 8.0

### Description:
In v9.15.0 calling the route() helper with model parameters in a non-associative array will result in an ErrorException "Unidentified array key 0" being thrown in Route.php line 539.
I realize that the use of non-associative arrays is no longer documented, but as long as the order of the parameters was correct, it has worked until v9.14.0. 
If there have been any warnings in the upgrade guides that this would happen, I must have missed it. And it's especially unexpected in a minor release.

### Steps To Reproduce:
```php
route('route.name', [$someModel]); // Throws ErrorException
route('route.name', $someModel); // Also worked up until v9.14.0, now it throws ErrorException
```
<!-- If possible, please provide a GitHub repository to demonstrate your issue -->
<!-- laravel new bug-report --github="--public" -->


Pull request description:
[9.x] Handle undefined array key error
Fixes #42605 

Oh boy, the gift that keeps on giving. Looks like there's yet another edge case.

## Summary

This PR fixes a regression when trying passing a model to the `route` helper for a route without route parameters.

```php
$model = new User(['id' => 1]);

Route::get('/foo')->name('foo');

route('foo', $model); // Used to return `/foo?1`, now throws an exception
```

While I think this behavior is pretty weird, I guess it shouldn't break between minor versions.

Patch:
diff --git a/src/Illuminate/Routing/Route.php b/src/Illuminate/Routing/Route.php
index 941a1ff0b5..fe88d0d6f2 100755
--- a/src/Illuminate/Routing/Route.php
+++ b/src/Illuminate/Routing/Route.php
@@ -536,7 +536,13 @@ public function signatureParameters($conditions = [])
     public function bindingFieldFor($parameter)
     {
         if (is_int($parameter)) {
-            $parameter = $this->parameterNames()[$parameter];
+            $parameters = $this->parameterNames();
+
+            if (! isset($parameters[$parameter])) {
+                return null;
+            }
+
+            $parameter = $parameters[$parameter];
         }
 
         return $this->bindingFields[$parameter] ?? null;


Test patch:
diff --git a/tests/Routing/RoutingUrlGeneratorTest.php b/tests/Routing/RoutingUrlGeneratorTest.php
index f59a61d071..9631519477 100755
--- a/tests/Routing/RoutingUrlGeneratorTest.php
+++ b/tests/Routing/RoutingUrlGeneratorTest.php
@@ -373,6 +373,24 @@ public function testRoutableInterfaceRoutingWithCustomBindingField()
         $this->assertSame('/foo/test-slug', $url->route('routable', [$model], false));
     }
 
+    public function testRoutableInterfaceRoutingAsQueryString()
+    {
+        $url = new UrlGenerator(
+            $routes = new RouteCollection,
+            Request::create('http://www.foo.com/')
+        );
+
+        $route = new Route(['GET'], 'foo', ['as' => 'query-string']);
+        $routes->add($route);
+
+        $model = new RoutableInterfaceStub;
+        $model->key = 'routable';
+
+        $this->assertSame('/foo?routable', $url->route('query-string', $model, false));
+        $this->assertSame('/foo?routable', $url->route('query-string', [$model], false));
+        $this->assertSame('/foo?foo=routable', $url->route('query-string', ['foo' => $model], false));
+    }
+
     public function testRoutableInterfaceRoutingWithSeparateBindingFieldOnlyForSecondParameter()
     {
         $url = new UrlGenerator(