diff --git a/CHANGELOG-5.3.md b/CHANGELOG-5.3.md index 32d2d4c4a070..f328d9395653 100644 --- a/CHANGELOG-5.3.md +++ b/CHANGELOG-5.3.md @@ -16,8 +16,6 @@ - Don't report exceptions inside queue worker signal handler ([#16738](https://github.com/laravel/framework/pull/16738)) - Kill timed out queue worker process ([#16746](https://github.com/laravel/framework/pull/16746)) - Removed unnecessary check in `ScheduleRunCommand::fire()` ([#16752](https://github.com/laravel/framework/pull/16752)) -- Improved performance of `Str::startsWith()` ([#16761](https://github.com/laravel/framework/pull/16761)) -- Improved handling of numeric values in `Str::startsWith()` ([#16770](https://github.com/laravel/framework/pull/16770)) ### Fixed - Added file existance check to `AppNameCommand::replaceIn()` to fix [#16575](https://github.com/laravel/framework/pull/16575) ([#16592](https://github.com/laravel/framework/pull/16592)) diff --git a/src/Illuminate/Routing/Router.php b/src/Illuminate/Routing/Router.php index cbfcdb224757..ef866235fdec 100644 --- a/src/Illuminate/Routing/Router.php +++ b/src/Illuminate/Routing/Router.php @@ -804,7 +804,7 @@ public function substituteImplicitBindings($route) ! $route->getParameter($parameter->name) instanceof Model) { $method = $parameter->isDefaultValueAvailable() ? 'first' : 'firstOrFail'; - $model = $class->newInstance(); + $model = $this->container->make($class->name); $route->setParameter( $parameter->name, $model->where( diff --git a/tests/Routing/RoutingRouteTest.php b/tests/Routing/RoutingRouteTest.php index f0be3e4bd690..c0ffb9bba5f2 100644 --- a/tests/Routing/RoutingRouteTest.php +++ b/tests/Routing/RoutingRouteTest.php @@ -1155,6 +1155,25 @@ public function testImplicitBindingsWithOptionalParameter() $router->dispatch(Request::create('bar', 'GET'))->getContent(); } + public function testImplicitBindingThroughIOC() + { + $phpunit = $this; + $container = new Container; + $router = new Router(new Dispatcher, $container); + $container->singleton(Registrar::class, function () use ($router) { + return $router; + }); + + $container->bind('RoutingTestUserModel', 'RoutingTestExtendedUserModel'); + $router->get('foo/{bar}', [ + 'middleware' => SubstituteBindings::class, + 'uses' => function (RoutingTestUserModel $bar) use ($phpunit) { + $phpunit->assertInstanceOf(RoutingTestExtendedUserModel::class, $bar); + }, + ]); + $router->dispatch(Request::create('foo/baz', 'GET'))->getContent(); + } + public function testDispatchingCallableActionClasses() { $router = $this->getRouter(); @@ -1390,6 +1409,10 @@ public function firstOrFail() } } +class RoutingTestExtendedUserModel extends RoutingTestUserModel +{ +} + class ActionStub { public function __invoke()