Fix parameter validation when generating relative URLs to routes with domain parameters #755
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.
Laravel requires that domain parameters always be passed to the
route()
helper, even if the user is generating a relative URL and the domain parameters will not appear in the final output. Omitting the parameter results in an error. Depending how the parameters are passed the error will be different, but the underlying problem is the same:Ziggy currently behaves exactly the opposite way—it effectively prohibits domain parameters from being passed to the
route()
helper and handled as such, if the user is generating a relative URL:So Laravel requires that all required parameters be provided, and Ziggy requires that only the required parameters that will appear in the output be provided.
This was almost certainly unintentional, and a side effect of how we replace parameters in the URL. Ziggy generates a template of the final output of the
route()
helper, which, if therelative
option was passed, only contains the route path, and then replaces all the parameters in that template. Laravel generates a template of the entire URL, replaces all the parameters in that template, and then returns only the path if the relative option was passed.I'm going to propose that we update Ziggy to match Laravel's behaviour, which is a large change, but justified in my opinion since it fixes what I believe is a large bug.
For now this PR includes a failing test demonstrating the issue.