1
0
Fork 0
mirror of https://github.com/archtechx/tenancy.git synced 2026-06-20 22:54:05 +00:00
tenancy/tests/Bootstrappers
lukinovec dfb0e1ad66
TenancyUrlGenerator: override toRoute(), refactor (#1439)
This PR adds the `toRoute()` method override to `TenancyUrlGenerator`.
`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 the `route()` method
override `TenancyUrlGenerator` had 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 in `TenancyUrlGenerator`) in
`Livewire::getUpdateUri()`. Now, it uses `toRoute()`
(544aa3dfb8 (diff-e7609f8b0a60bde5a85067803d4e2f08f235c7cee9225a51ea67a85ff9a1d694R52)),
which didn't automatically swap the route for its 'tenant.'-prefixed
equivalent in tenant context (until now). So for the Livewire
integration to work with path identification, we need to override
`toRoute()` as described.

The `temporarySignedRoute()` override got removed because
`temporarySignedRoute()` calls `route()` under the hood, there's no need
to specifically override `temporarySignedRoute()`.

> Note: Browsing old convos, it seems like the `temporarySignedRoute()`
override was needed to make Livewire file uploads work with path
identification, but it's not needed anymore. TenancyUrlGenerator had
some changes since then, and now, I can't see the _exact_ reason why we
needed the override (`temporarySignedRoute()` uses `route()` under the
hood, so the only thing that should really matter is overriding
`route()`/`toRoute()`). It was likely a leftover from some older
implementation.

The `route()` override got simplified. Since `route()` uses `toRoute()`
under the hood, the `route()` override only has to have the prefixing
logic. The rest is delegated to `toRoute()`.

> Note: Even though we override `toRoute()` now which `route()` uses for
generating the URLs, we still need to override `route()` for its
`$this->routes->getByName($name)` call to receive the prefixed name. For
example, if `route()` wasn't overridden, and we only had one route:
`tenant.foo` (no central `foo` route), and we'd call `route('foo')`,
we'd get an exception saying that route "foo" wasn't found, even if
automatic route name prefixing was enabled and `toRoute()` was
overridden. With the `route()` override, `route('foo')` acts as if we
passed 'tenant.foo' instead of 'foo'.

Comments in TenancyUrlGenerator and UrlGeneratorBootstrapper got updated
to be more accurate. All _intentionally_ affected methods are listed in
TenancyUrlGenerator's docblock.

---------

Co-authored-by: Samuel Stancl <samuel@archte.ch>
2026-06-06 14:52:37 -07:00
..
BootstrapperTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
BroadcastChannelPrefixBootstrapperTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
BroadcastingConfigBootstrapperTest.php Resolve test to-dos (#45) 2024-04-18 00:22:03 +02:00
CacheTagsBootstrapperTest.php [4.x] Support database cache store tenancy (#1290) (resolve #852) 2025-08-08 00:54:01 +02:00
CacheTenancyBootstrapperTest.php Resolve test to-dos (#45) 2024-04-18 00:22:03 +02:00
DatabaseSessionBootstrapperTest.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
DatabaseTenancyBootstrapper.php [4.x] Laravel 12 support (#1321) 2025-02-25 16:26:18 +01:00
FilesystemTenancyBootstrapperTest.php Change tenant storage listeners into jobs (#1446) 2026-04-22 16:45:54 +02:00
FortifyRouteBootstrapperTest.php [4.x] Resolve testing todos (#1361) 2025-08-03 23:21:03 +02:00
MailConfigBootstrapper.php rename mail bootstrapper test file 2024-09-27 21:03:39 +02:00
RootUrlBootstrapperTest.php [4.x] Improve RootUrl and UrlGenerator bootstrappers (#1294) 2025-01-16 10:30:06 +01:00
UrlGeneratorBootstrapperTest.php TenancyUrlGenerator: override toRoute(), refactor (#1439) 2026-06-06 14:52:37 -07:00