[11.x] Add webPrefix
support to the withRouting method
#50324
Closed
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.
Overview
This Pull Request proposes the addition of the
webPrefix
parameter to thewithRouting
method.Similarly to the
apiPrefix
parameter, thewebPrefix
parameter allows the user to specify a prefix for the web routes, if needed.Changes Proposed:
$webPrefix
has been added to thewithRouting()
method signature.buildRoutingCallback()
method has been modified to accept the$webPrefix
parameter and use it to prefix web routes.Why is this change important?
Laravel 11 currently provides a way to specify a prefix for API routes using the
apiPrefix
parameter. However, there is no 'fluent' way to prefix the web routes.With this change, users will be able to specify a prefix for web routes if needed. This will avoid the manual addition of prefixes in the
web.php
file, which in my opinion, would not be the best way to handle this.By adding the
webPrefix
parameter, web routes can be prefixed in a similar way to API routes, resulting in more consistent code.Use Cases
Case 1
When the user wants to group all web routes under a specific URL path, they can prefix the web routes with a specific string.
Case 2
From my own case, I have a Laravel application that is used as an API subdomain. However, I do not use the
/api
prefix for the API routes. Instead, I leave it blank or use it with something else. Consider the URL likeapi.example.com/users
.Additionally, I serve a few web routes in my application, and all these routes are grouped under the
/content
prefix. So, if I wanted to serve a web route for a file called "my-file.pdf", the URL would beapi.example.com/content/my-file.pdf
.By making these changes to my application, I can use the
/content
prefix for my web routes and organize it the same way as my API routes.Additional Context
As the
webPrefix
parameter in thewithRouting
method is set to blank (empty string), it shouldn't change or break any existing code.Lastly, I believe that the
webPrefix
is less likely to be used, so it was set after theapiPrefix
in thewithRouting
method signature.