Skip to content
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

[12.x] Route aliases #51307

Closed
wants to merge 3 commits into from
Closed

[12.x] Route aliases #51307

wants to merge 3 commits into from

Conversation

7snovic
Copy link

@7snovic 7snovic commented May 5, 2024

Adding the ability to alias a named route by another name/alias.

Motivation

Considering the following scenario, we have a package that implements some UI features with a basic routes, and another package that implementing some functionalities that needed to be used within the first package, if the first package does not allow configuring it's used routes, there will be no direct way to integrate the two packages.
Although, the previous scenario is considered as an edge-case due to the bad design that had been followed in the first package, yet, aliasing routes remain a good features that may be added value if it had been implemented in Laravel.

Usage

Route::get('some-path/', 'Controller@method')->name('base-name');

Route::alias('alias-route-name', 'base-name');

// .... now we can use the defined alias as a route name when we try to retrieve the route info, for example
return redirect('alias-route-name');

reference discussion #51306

@crynobone
Copy link
Member

Please describe the reasoning for this PR instead of just linking to a discussion.

@driesvints
Copy link
Member

Feel free to mark this as ready once you added a thorough description. Thanks

@driesvints driesvints marked this pull request as draft May 6, 2024 09:42
@driesvints driesvints changed the title [WIP] Route aliases [12.x] Route aliases May 6, 2024
@7snovic
Copy link
Author

7snovic commented May 7, 2024

@crynobone @driesvints I'd added some description to the PR. Not sure of the process, I just followed the Contribution section in the documentation, so, I am not sure if we should continue in the discussion approach or in the PR.

@driesvints driesvints marked this pull request as ready for review May 7, 2024 15:07
@7snovic 7snovic marked this pull request as draft May 7, 2024 20:33
@7snovic
Copy link
Author

7snovic commented May 7, 2024

todo:

  • throw an exception in case if the alias is already exists as a named route
  • show the aliases in the route:list artisan command
  • add test cases

@morloderex
Copy link
Contributor

How will this work with route caching?

@7snovic
Copy link
Author

7snovic commented May 9, 2024

@morloderex good point, will consider checking it, thank you.

@7snovic 7snovic marked this pull request as ready for review May 18, 2024 17:11
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If possible, please consider releasing your code as a package so that the community can still take advantage of your contributions!

If you feel absolutely certain that this code corrects a bug in the framework, please "@" mention me in a follow-up comment with further explanation so that GitHub will send me a notification of your response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants