Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

make withoutScopedBindings usable on RouteRegistrar #54592

Merged
merged 1 commit into from
Feb 13, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Illuminate/Routing/RouteRegistrar.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ class RouteRegistrar
'scopeBindings',
'where',
'withoutMiddleware',
'withoutScopedBindings',
];

/**
Expand All @@ -84,6 +85,7 @@ class RouteRegistrar
protected $aliases = [
'name' => 'as',
'scopeBindings' => 'scope_bindings',
'withoutScopedBindings' => 'scope_bindings',
'withoutMiddleware' => 'excluded_middleware',
];

Expand Down Expand Up @@ -127,6 +129,10 @@ public function attribute($key, $value)
);
}

if ($key === 'withoutScopedBindings') {
$value = false;
}

if ($value instanceof BackedEnum && ! is_string($value = $value->value)) {
throw new InvalidArgumentException("Attribute [{$key}] expects a string backed enum.");
}
Expand Down
44 changes: 44 additions & 0 deletions tests/Routing/RouteRegistrarTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -516,6 +516,50 @@ public function testRegisteringNonApprovedAttributesThrows()
});
}

public function testCanSetWithoutScopedBindings()
{
$route = $this->router->withoutScopedBindings()->get('users', function () {
return 'all-users';
});

$this->assertTrue($route->preventsScopedBindings());
}

public function testCanSetWithoutScopedBindingsOnGroup()
{
$this->router->withoutScopedBindings()->group(function ($router) {
$router->get('foo', function () {
return 'hello';
});
});

$route = $this->router->getRoutes()->getRoutes()[0];

$this->assertTrue($route->preventsScopedBindings());
}

public function testCanSetScopeBindings()
{
$route = $this->router->scopeBindings()->get('users', function () {
return 'all-users';
});

$this->assertTrue($route->enforcesScopedBindings());
}

public function testCanSetScopeBindingsOnGroup()
{
$this->router->scopeBindings()->group(function ($router) {
$router->get('foo', function () {
return 'hello';
});
});

$route = $this->router->getRoutes()->getRoutes()[0];

$this->assertTrue($route->enforcesScopedBindings());
}

public function testCanRegisterResource()
{
$this->router->middleware('resource-middleware')
Expand Down
Loading