@@ -114,7 +114,15 @@ public function route($name, $parameters = [], $absolute = true)
114114 throw new InvalidArgumentException ('Attribute [name] expects a string backed enum. ' );
115115 }
116116
117- [$ name , $ parameters ] = $ this ->prepareRouteInputs ($ name , Arr::wrap ($ parameters )); // @phpstan-ignore argument.type
117+ $ wrappedParameters = Arr::wrap ($ parameters );
118+
119+ [$ name , $ parameters ] = $ this ->prepareRouteInputs ($ name , $ wrappedParameters ); // @phpstan-ignore argument.type
120+
121+ if (isset ($ wrappedParameters [static ::$ bypassParameter ])) {
122+ // If the bypass parameter was passed, we need to add it back to the parameters after prepareRouteInputs() removes it,
123+ // so that the underlying toRoute() call in parent::route() can bypass the behavior modification as well.
124+ $ parameters [static ::$ bypassParameter ] = $ wrappedParameters [static ::$ bypassParameter ];
125+ }
118126
119127 return parent ::route ($ name , $ parameters , $ absolute );
120128 }
@@ -142,6 +150,25 @@ public function temporarySignedRoute($name, $expiration, $parameters = [], $abso
142150 return parent ::temporarySignedRoute ($ name , $ expiration , $ parameters , $ absolute );
143151 }
144152
153+ /**
154+ * Override the toRoute() method so that the route name gets prefixed
155+ * and the tenant parameter gets added when in tenant context.
156+ */
157+ public function toRoute ($ route , $ parameters , $ absolute )
158+ {
159+ $ name = $ route ->getName ();
160+
161+ if ($ name ) {
162+ [$ prefixedName , $ parameters ] = $ this ->prepareRouteInputs ($ name , Arr::wrap ($ parameters )); // @phpstan-ignore argument.type
163+
164+ if ($ prefixedName !== $ name && $ tenantRoute = $ this ->routes ->getByName ($ prefixedName )) {
165+ $ route = $ tenantRoute ;
166+ }
167+ }
168+
169+ return parent ::toRoute ($ route , $ parameters , $ absolute );
170+ }
171+
145172 /**
146173 * Return bool indicating if the bypass parameter was in $parameters.
147174 */
0 commit comments