Return a literal string from route() when generating a URL #336
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change would make using the
route()
function a little cleaner by removing the need to ever call.url()
, bring its behaviour closer to matching Laravel'sroute()
helper, and resolve a very annoying quirk with axios that required calling.url()
to ensure that CSRF tokens are attached to the request.When no arguments are passed to
route()
, it will continue to return aRouter
instance:However, now, if it's passed a
name
argument, it generates the URL and returns a string directly:This PR also:
Removes the
.with()
methodThis method was going to be deprecated in
1.0
since it isn't really necessary, parameters should always be passed as the second argument toroute()
.Removes the
.withQuery()
methodQuery parameters can also be passed in the second argument to
route()
, mixed in with regular route parameters.For edge cases like where a query parameter has exactly the same name as a route parameter, this PR adds a special
_query
parameter that will be added directly to the query string:Removes the
.url()
methodCalling
.url()
is no longer possible or necessary sinceroute(...)
with any arguments returns a string. To reduce repetition it was removed and its functionality was moved to the existing.toString()
method on the Router class.