[4.x] TenancyUrlGenerator: override toRoute()#1439
Conversation
Also update `route()` override since `parent::route()` calls `toRoute()` under the hood (similarly to how `parent::temporarySignedRoute()` calls `route()`)
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #1439 +/- ##
============================================
+ Coverage 86.03% 86.06% +0.02%
- Complexity 1156 1157 +1
============================================
Files 184 184
Lines 3381 3380 -1
============================================
Hits 2909 2909
+ Misses 472 471 -1 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
The `toRoute()` and `route()` overrides cover `temporarySignedRoute())`, so we don't need to specifically override `temporarySIgnedRoute()` anymore. `route()` override got simplified since everything except for the name prefixing is delegated to the lower-level `toRoute()` method.
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughCentralized route-name prefixing and tenant-parameter handling by introducing a Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Overrides/TenancyUrlGenerator.php`:
- Around line 141-149: The parameter mutation is skipped for unnamed Route
objects because $route->getName() gates the call to prepareRouteInputs; change
the logic in TenancyUrlGenerator::toRoute so you always call
$this->prepareRouteInputs($name, Arr::wrap($parameters)) (or call it with
null/$name when route has no name) to apply tenant-parameter injection and
bypass-parameter removal, but keep the route swap conditional: only replace
$route when $prefixedName !== $name and $this->routes->getByName($prefixedName)
returns a route; ensure prepareRouteInputs and the passTenantParameterToRoutes
behavior run even when $route->getName() is falsy before delegating to
parent::toRoute().
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 17d8031d-e2be-43de-9b4c-44e8b71136d2
📒 Files selected for processing (3)
src/Bootstrappers/UrlGeneratorBootstrapper.phpsrc/Overrides/TenancyUrlGenerator.phptests/Bootstrappers/UrlGeneratorBootstrapperTest.php
If an unnamed route is passed to url()->toRoute(), the generated URL will receive the tenant parameter as long as the bypass parameter wasn't passed. Also remove the bypass parameter from the generated URL.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@src/Overrides/TenancyUrlGenerator.php`:
- Around line 128-130: The route() method currently calls prepareRouteInputs()
and discards the mutated $parameters, causing duplicate work and potential side
effects; create a small helper (e.g., normalizeRouteName or prepareRouteName) in
the TenancyUrlGenerator class that performs only the name normalization logic
extracted from prepareRouteInputs() and returns the normalized $name without
mutating $parameters, then update route() to call that helper and pass the
original $parameters into parent::route($name, $parameters, $absolute); keep
prepareRouteInputs() and toRoute() unchanged so full parameter resolution still
happens only when needed.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: ASSERTIVE
Plan: Pro
Run ID: 1ef2ed10-fc71-412c-80f0-c96ee9ac799c
📒 Files selected for processing (2)
src/Overrides/TenancyUrlGenerator.phptests/Bootstrappers/UrlGeneratorBootstrapperTest.php
|
@coderabbitai full review |
✅ Actions performedFull review triggered. |
This PR adds the
toRoute()method override toTenancyUrlGenerator.toRoute()now attempts to find a tenant equivalent of the passed route (= a route with the same name as the passed one, but with the tenant prefix) and generates URL for the tenant route. This behavior can be bypassed using the bypass parameter, like with theroute()method overrideTenancyUrlGeneratorhad until now.The primary reason for adding this is that Livewire v4 no longer uses the
route()helper (which automatically prefixes the passed route name because of the override inTenancyUrlGenerator) inLivewire::getUpdateUri(). Now, it usestoRoute()(livewire/livewire@544aa3d#diff-e7609f8b0a60bde5a85067803d4e2f08f235c7cee9225a51ea67a85ff9a1d694R52), which didn't automatically swap the route for its 'tenant.'-prefixed equivalent in tenant context. So for the Livewire integration to work with path identification, we need to overridetoRoute()as described.The
temporarySignedRoute()override got removed becausetemporarySignedRoute()callsroute()under the hood, there's no need to specifically overridetemporarySignedRoute().The
route()override got simplified. Sinceroute()usestoRoute()under the hood, theroute()override only has to have the prefixing logic. The rest gets delegated totoRoute().Comments in TenancyUrlGenerator and UrlGeneratorBootstrapper got updated to be more accurate. All intentionally affected methods are listed in TenancyUrlGenerator's docblock.
Summary by CodeRabbit
Improvements
Documentation
Tests