-
Notifications
You must be signed in to change notification settings - Fork 11.7k
[5.1] Fix domain wildcard group in routes and url generation #7397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…d routes A proposed solution for issue laravel#7366. For the route method if there are no parameters, get the parameters from the current request to correctly parse a URL. ~~~ Route::group( [ 'domain' => '{subdomain}.domain.com', ], function ($router) { Route::get( '/', [ 'uses' => function ($subdomain) { return route('subhome'); }, 'as' => 'subhome' ] ); } ); ~~~ Currently this would generate: ~~~ http://%7Bsubdomain%7D.domain.com ~~~ By getting the parameters from the current request it now generates this: ~~~ http://blah.domain.com ~~~ Not sure if this is the best "solution" just thought I would share :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No need for the else block. Do this:
if (count($parameters) > 1) {
return $this->toRoute($route, $parameters, $absolute);
}
return $this->toRoute($route, $route->bind($this->getRequest())->parameters(), $absolute);|
Made those changes, thanks! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One too many tabs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, you need the new lines as I put them. Don't remove them.
|
Better to replace this whole thing with this code: public function route($name, $parameters = array(), $absolute = true)
{
if (is_null($route = $this->routes->getByName($name)))
{
throw new InvalidArgumentException("Route [{$name}] not defined.");
}
if (count($parameters) > 0) {
return $this->toRoute($route, $parameters, $absolute);
}
return $this->toRoute($route, $route->bind($this->getRequest())->parameters(), $absolute);
} |
|
Still don't really like this. |
Allow the UrlGenerator
route(...)function to get its parameters from the current request as suggested in issue #7366. With this you can either explicitly set the parameters or get them from the request.Example:
You can use
route('subhome')with no other options and have it generate a correct URL.Just a suggestion :)