Skip to content

Commit e846535

Browse files
authored
Allow "missing" method to be used on route groups (#49144)
* Allow missing method to be used on route groups * Code style
1 parent cc374af commit e846535

File tree

3 files changed

+27
-2
lines changed

3 files changed

+27
-2
lines changed

src/Illuminate/Routing/RouteRegistrar.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
* @method \Illuminate\Routing\RouteRegistrar controller(string $controller)
2121
* @method \Illuminate\Routing\RouteRegistrar domain(string $value)
2222
* @method \Illuminate\Routing\RouteRegistrar middleware(array|string|null $middleware)
23+
* @method \Illuminate\Routing\RouteRegistrar missing(\Closure $missing)
2324
* @method \Illuminate\Routing\RouteRegistrar name(string $value)
2425
* @method \Illuminate\Routing\RouteRegistrar namespace(string|null $value)
2526
* @method \Illuminate\Routing\RouteRegistrar prefix(string $prefix)
@@ -65,6 +66,7 @@ class RouteRegistrar
6566
'controller',
6667
'domain',
6768
'middleware',
69+
'missing',
6870
'name',
6971
'namespace',
7072
'prefix',

tests/Routing/RouteRegistrarTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -498,9 +498,9 @@ public function testRouteGroupChaining()
498498
public function testRegisteringNonApprovedAttributesThrows()
499499
{
500500
$this->expectException(BadMethodCallException::class);
501-
$this->expectExceptionMessage('Method Illuminate\Routing\RouteRegistrar::missing does not exist.');
501+
$this->expectExceptionMessage('Method Illuminate\Routing\RouteRegistrar::unsupportedMethod does not exist.');
502502

503-
$this->router->domain('foo')->missing('bar')->group(function ($router) {
503+
$this->router->domain('foo')->unsupportedMethod('bar')->group(function ($router) {
504504
//
505505
});
506506
}

tests/Routing/RoutingRouteTest.php

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1883,6 +1883,29 @@ public function testImplicitBindingsWithMissingModelHandledByMissing()
18831883
$this->assertEquals(302, $response->getStatusCode());
18841884
}
18851885

1886+
public function testImplicitBindingsWithMissingModelHandledByMissingOnGroupLevel()
1887+
{
1888+
$router = $this->getRouter();
1889+
$router->as('foo.')
1890+
->missing(fn () => new RedirectResponse('/', 302))
1891+
->group(function () use ($router) {
1892+
$router->get('foo/{bar}', [
1893+
'middleware' => SubstituteBindings::class,
1894+
'uses' => function (RouteModelBindingNullStub $bar = null) {
1895+
$this->assertInstanceOf(RouteModelBindingNullStub::class, $bar);
1896+
1897+
return $bar->first();
1898+
},
1899+
]);
1900+
});
1901+
1902+
$request = Request::create('foo/taylor', 'GET');
1903+
1904+
$response = $router->dispatch($request);
1905+
$this->assertTrue($response->isRedirect('/'));
1906+
$this->assertEquals(302, $response->getStatusCode());
1907+
}
1908+
18861909
public function testImplicitBindingsWithOptionalParameterWithNoKeyInUri()
18871910
{
18881911
$router = $this->getRouter();

0 commit comments

Comments
 (0)