Skip to content

Commit 70f2f01

Browse files
authored
Revert "[8.x] Respect custom route key with explicit route model binding (#36375)" (#36449)
This reverts commit 8c5292e.
1 parent e3f48f7 commit 70f2f01

File tree

3 files changed

+5
-36
lines changed

3 files changed

+5
-36
lines changed

src/Illuminate/Routing/RouteBinding.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,15 @@ public static function forCallback($container, $binder)
3333
*/
3434
protected static function createClassBinding($container, $binding)
3535
{
36-
return function ($value, $route, $key) use ($container, $binding) {
36+
return function ($value, $route) use ($container, $binding) {
3737
// If the binding has an @ sign, we will assume it's being used to delimit
3838
// the class name from the bind method name. This allows for bindings
3939
// to run multiple bind methods in a single class for convenience.
4040
[$class, $method] = Str::parseCallback($binding, 'bind');
4141

4242
$callable = [$container->make($class), $method];
4343

44-
return $callable($value, $route, $key);
44+
return $callable($value, $route);
4545
};
4646
}
4747

@@ -57,7 +57,7 @@ protected static function createClassBinding($container, $binding)
5757
*/
5858
public static function forModel($container, $class, $callback = null)
5959
{
60-
return function ($value, $route, $key) use ($container, $class, $callback) {
60+
return function ($value) use ($container, $class, $callback) {
6161
if (is_null($value)) {
6262
return;
6363
}
@@ -67,7 +67,7 @@ public static function forModel($container, $class, $callback = null)
6767
// throw a not found exception otherwise we will return the instance.
6868
$instance = $container->make($class);
6969

70-
if ($model = $instance->resolveRouteBinding($value, $route->bindingFieldFor($key))) {
70+
if ($model = $instance->resolveRouteBinding($value)) {
7171
return $model;
7272
}
7373

src/Illuminate/Routing/Router.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -840,7 +840,7 @@ public function substituteImplicitBindings($route)
840840
*/
841841
protected function performBinding($key, $value, $route)
842842
{
843-
return call_user_func($this->binders[$key], $value, $route, $key);
843+
return call_user_func($this->binders[$key], $value, $route);
844844
}
845845

846846
/**

tests/Routing/RoutingRouteTest.php

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
use Illuminate\Routing\UrlGenerator;
3030
use Illuminate\Support\Str;
3131
use LogicException;
32-
use Mockery;
3332
use PHPUnit\Framework\TestCase;
3433
use stdClass;
3534
use Symfony\Component\HttpFoundation\Response as SymfonyResponse;
@@ -939,36 +938,6 @@ public function testModelBinding()
939938
$this->assertSame('TAYLOR', $router->dispatch(Request::create('foo/taylor', 'GET'))->getContent());
940939
}
941940

942-
public function testModelBindingWithCustomKey()
943-
{
944-
// Create the router.
945-
$container = new Container();
946-
$router = new Router(new Dispatcher(), $container);
947-
$container->singleton(Registrar::class, function () use ($router) {
948-
return $router;
949-
});
950-
951-
$router->get('foo/{bar:custom}', ['middleware' => SubstituteBindings::class, 'uses' => function ($name) {
952-
return $name;
953-
}]);
954-
$router->model('bar', RouteModelBindingStub::class);
955-
956-
// Mock the stub so we can verify that the method is called with custom key.
957-
$mock = $container->instance(
958-
RouteModelBindingStub::class,
959-
Mockery::mock(RouteModelBindingStub::class),
960-
);
961-
962-
$mock->shouldReceive('resolveRouteBinding')
963-
->with('taylor', 'custom')
964-
->once()
965-
->andReturn('TAYLOR');
966-
967-
$this->assertSame('TAYLOR', $router->dispatch(Request::create('foo/taylor', 'GET'))->getContent());
968-
969-
Mockery::close();
970-
}
971-
972941
public function testModelBindingWithNullReturn()
973942
{
974943
$this->expectException(ModelNotFoundException::class);

0 commit comments

Comments
 (0)