EDIT (platform sepcs):
It appears that as soon as you call php artisan route:cache, the GET / route returns a 405 Method Not Allowed error. I originally encountered this in a running project, but after updating all packages, the issue still persisted.
I've browsed through the issues and there appears to have been done some work related to routing, mainly https://github.com/laravel/framework/issues/32228 , https://github.com/laravel/framework/issues/31756 and https://github.com/laravel/framework/issues/31768 , however I couldnt track down any issue that could remain.
I can reproduce it using a fresh Laravel project:
composer global require laravel/installerlaravel new laravel-route-bugcomposer installroutes/api.php (not cacheable because closure)routes/web.php to:Route::get('/', ['uses' => 'Controller@index', 'as' => 'index.index']);app\Http\Controllers\Controller.php:public function index() {
return 'this is index';
}
.env copy from .env.example and call php artisan key:generatephp artisan route:cache (should execute successfully now)The GET method is not supported for this route. Supported methods: HEAD.reproduction works right here! you might be making a simple mistake!
or this might not be a framework issue!
I followed your steps and can't recreate it either. Will ping @driesvints just in case.
I have some additional information which I encountered during testing:
I always develop my applications using simple http://localhost/someproject/public URLs. This has always worked perfectly (at least in v6.x, it could be that I just haven't encountered this issue since v7.0.0).
I notice that the issue is gone when I create a vhost for laravel-project.loc and point it to the correct directory, and then call the application using http://laravel-project.loc.
For what it's worth, here's a gist of the route file that is being generated:
https://gist.github.com/bert-w/1ea42bb124de4b857d62f04d0ad856aa
I tried tracing down the issue through xdebug, but it sent me far into the Symfony routing package, to be exact here: https://github.com/symfony/routing/blob/master/Matcher/Dumper/CompiledUrlMatcherTrait.php#L90
This line tries to find the correct route in the compiled routes file app/bootstrap/cache/routes-v7.php (see the gist above), but it does so using the variable $trimmedPathinfo = '/someproject/public' (which results in no matches, since it has to be / to be able to find the correct route).
I wish I knew where to look to find the issue; there's just a lot to go through.
@bert-w we don't support Laravel in a subdirectory: https://laravel.com/docs/7.x/installation#directory-configuration

Thanks, I didnt know about that restriction. Something did change between 6.x and 7.x that caused this to break though. Quite possibly one of the updated Symfony modules.
It's just a minor issue then if this only affects a development environment. I can live with not-executing php artisan route:cache on my local environment :)
If it helps @bert-w - We hit this on select environments during upgrades to L7. We tracked it down to a trailing slash on url. Which makes sense with the comments about subdirectories.
Some environments had like
foo.example.com/
and the working ones
foo.example.com
So the URL would become
foo.example.com//api/bar
and die out
{
"message": "The POST method is not supported for this route. Supported methods: GET, HEAD."
}
I imagine something in newer Symfony is a bit more strict, but boy that sent me on a search.
I can confirm I have the same problem and website is under http://my-domain/apps123 who is redirected to http://my-domain/apps123/
Please try to reproduce with sub folder domain, and let us know if it works or not.
Also I confirm if you don't remove the single route from routes/api.php (not cacheable because closure) it works fine because the cache is not enabled, but also then it falls under this issues:
So in our case the problem is definitively with the caching aka artisan route:cache
EDIT:
I found a solution to bypass the problem. If you add the route "/apps123" it works with the caching.
Most helpful comment
@bert-w we don't support Laravel in a subdirectory: https://laravel.com/docs/7.x/installation#directory-configuration