Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

rsy644's avatar

Upgrading of Laravel from 8.x to 9.x: routing error.

Hi there, I am attempting to upgrade a laravel app I have from version 8.x to 9.x. I have updated my composer.json file with the new versions:

laravel/framework to ^9.0
nunomaduro/collision to ^6.1

and I have run composer update. However, when accessing the home page of my site now, I run into the following error message: The GET method is not supported for route /. Supported methods: HEAD.

I have tried running php artisan optimize, and php artisan route:cache, but to no effect.

Here is my routes file, and the body of my main controller:

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\ProductController;
use App\Http\Controllers\AdminController;
use App\Http\Controllers\SubscriptionController;
use App\Http\Controllers\MailController;

Route::get('/', [ProductController::class, 'index'])->name('products.index');
Route::get('/create/{id}', [ProductController::class, 'create'])->name('products.create');

etc.

Controller:

<?php

namespace App\Http\Controllers;
use App\Models\Product;
use App\Models\Customer;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;

class ProductController
{
    /**
     * Display a listing of the resource.
     *
     * @return \Illuminate\Http\Response
     * @method('GET')
     */

    public function index()
    {
		$products = Product::all();
        return view('products.index')->with('products', $products);
    }

I would be grateful as to any suggestions as to how to resolve this.

Thanks,

Robert

0 likes
11 replies
amitsolanki24_'s avatar

@rsy644 Hey robert, did you run php artisan route:clear

Try to run php artisan server if route:clear dont work.

rsy644's avatar

Hi Amit, Thanks for your reply, I have tried running php artisan route:clear. I get the homepage back and everything appears, but when I navigate to any internal route, I get taken to a page which says 'Not Found'. When I run php artisan route:cache, or php artisan optimize, I am taken back to the error message that I mentioned in my first post about the GET method. Any suggestions here? Thanks, Robert

gych's avatar

@rsy644 Try to run

composer dump-autoload

After that

php artisan route:clear

Don't use php artisan optimize or php artisan route:cache locally

1 like
rsy644's avatar

@gych Thanks for your suggestion, I have given it a try on my local server. Unfortumately, the routing problem is still there. Maybe there's something else I'm missing, perhaps related to .htaccess? The only thing I can think of doing is maybe installing Laravel afresh and starting again.

gych's avatar

@rsy644 When you run php artisan route:list in your terminal which results do you get? Can you see the GET route correctly in the route list?

rsy644's avatar

Hi @gych, yes I can see that the create route is in there, it is ten or so lines down the page. This is what I get when I run the php artisan route:list command:

  GET|HEAD   / .............................................................. products.index › ProductController@index
  GET|HEAD   _dusk/login/{userId}/{guard?} .......................... dusk.login › Laravel\Dusk › UserController@login
  GET|HEAD   _dusk/logout/{guard?} ................................ dusk.logout › Laravel\Dusk › UserController@logout
  GET|HEAD   _dusk/user/{guard?} ...................................... dusk.user › Laravel\Dusk › UserController@user
  POST       _ignition/execute-solution ignition.executeSolution › Spatie\LaravelIgnition › ExecuteSolutionController
  GET|HEAD   _ignition/health-check ............ ignition.healthCheck › Spatie\LaravelIgnition › HealthCheckController
  POST       _ignition/update-config ......... ignition.updateConfig › Spatie\LaravelIgnition › UpdateConfigController
  GET|HEAD   captcha/api/{config?} .................................... Mews\Captcha › CaptchaController@getCaptchaApi
  GET|HEAD   captcha/{config?} ........................................... Mews\Captcha › CaptchaController@getCaptcha
  GET|HEAD   create/{id} .................................................. products.create › ProductController@create
  GET|HEAD   login ........................................................ login › Auth\LoginController@showLoginForm
  POST       login ........................................................................ Auth\LoginController@login
  POST       logout ............................................................. logout › Auth\LoginController@logout
  GET|HEAD   password/confirm ...................... password.confirm › Auth\ConfirmPasswordController@showConfirmForm
  POST       password/confirm ................................................. Auth\ConfirmPasswordController@confirm
  POST       password/email ........................ password.email › Auth\ForgotPasswordController@sendResetLinkEmail
  GET|HEAD   password/reset ..................... password.request › Auth\ForgotPasswordController@showLinkRequestForm
  POST       password/reset ..................................... password.update › Auth\ResetPasswordController@reset
  GET|HEAD   password/reset/{token} ...................... password.reset › Auth\ResetPasswordController@showResetForm
  GET|HEAD   register ........................................ register › Auth\RegisterController@showRegistrationForm
  POST       register ............................................................... Auth\RegisterController@register
  GET|HEAD   show ............................................................. products.show › ProductController@show
  POST       store .......................................................... products.store › ProductController@store
  GET|HEAD   stripe/payment/{id} .......................... cashier.payment › Laravel\Cashier › PaymentController@show
  POST       stripe/webhook ...................... cashier.webhook › Laravel\Cashier › WebhookController@handleWebhook

As you can see, all the routes are there, but only the index route right at the very top seems to work. The create and show routes do not currently work, or the login routes.

rsy644's avatar

.htaccess file: C:\wamp64\www\Products-new\public

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    # Send Requests To Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>
rsy644's avatar

.htaccess file: C:\wamp64\www\Products-new

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ / [L,R=301]

    RewriteCond %{REQUEST_URI} !(\.css|\.js|\.png|\.jpg|\.gif|robots\.txt)$ [NC]
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_URI} !^/public/
    RewriteRule ^(css|js|images)/(.*)$ public// [L,NC]
</IfModule>
JussiMannisto's avatar

Your route URLs seem wrong. Normally in Laravel the create route is for presenting a model creation page and the show route is for showing a model. So the show route should have an {id} or a {product} route parameter. The create route shouldn't have any parameters.

rsy644's avatar

Hi Jussi and everyone, I seem to have fixed the problem. Its connected I think with my local server configuration and how it is started and stopped. I remember at one point I changed the port to :9312 (localhost), due to a port clash, but it seems to have somehow reverted back to :8000, and its running fine on there. So if I run php artisan serve, and go to :8000, it works ok. Thanks everyone for helping me fix the problem!

Please or to participate in this conversation.