laravel / framework

The Laravel Framework.
https://laravel.com
MIT License
32.63k stars 11.03k forks source link

inconsistent behavior in routes web.php file after php artisan optimize and before php artisan optimize. #53591

Closed rajatvermaiam closed 22 hours ago

rajatvermaiam commented 2 days ago

Laravel Version

11.31.0

PHP Version

8.3.13

Database Driver & Version

No response

Description

inconsistent behavior in routes web.php file after php artisan optimize and before php artisan optimize. i am providing steps to reproduce same behavior, it will be easy to understand there.

Steps To Reproduce

in web.php suppose we have these routes like below: Route::permanentRedirect('/', '/en'); //1st route Route::get('en', [HomeController::class, 'homepage']); //2nd route Route::post('/', [GetController::class, 'getMedia']); //3rd route

  1. Enter "php artisan optimize:clear" command.
  2. And submit an HTML form by " form action="{{route('download')}}" method="post" from second route. The third route is getting control.
  3. Enter "php artisan optimize" command.
  4. And submit an HTML form by " form action="{{route('download')}}" method="post" from second route.. The first route is getting control.

This is inconsistent behavior after optimize command .

crynobone commented 2 days ago

Hey there, thanks for reporting this issue.

We'll need more info and/or code to debug this further. Can you please create a repository with the command below, commit the code that reproduces the issue as one separate commit on the main/master branch and share the repository here?

Please make sure that you have the latest version of the Laravel installer in order to run this command. Please also make sure you have both Git & the GitHub CLI tool properly set up.

laravel new bug-report --github="--public"

Do not amend and create a separate commit with your custom changes. After you've posted the repository, we'll try to reproduce the issue.

Thanks!

rajatvermaiam commented 1 day ago

This is repo link that have same bug that i have described above: https://github.com/rajatvermaiam/bug-report

please follow above step to reproduce same bug in this repo.

macropay-solutions commented 1 day ago

Hi. If you put in your .htaccess a permanent redirect for a route, that will not take into account the verb so, it will redirect POST or GET request to a GET.

This is also the case for this situation. A feature might help restricting the permanent redirect by verb if not already possible.

crynobone commented 22 hours ago

Route::permanentRedirect() uses Route::any() and therefore can create a clashing route. Feel free if you want to submit a PR to improve generated routes via route:cache but we don't classify this as a bug.