Skip to content
Advertisement

Why laravel landing page route return MethodNotAllowedHttpException?

I’m using laravel 7.x. since function(){return view(welcome);} will produce an error when I run php artisan route:cache, so I write this code below to replace function():

Route::get('/', 'WelcomeController@index')->name('welcome');

It run well on php artisan serve command. But when i run directly from public folder, it produce exception MethodNotAllowedHttpException. I couldn’t find why it happened, could you help me why it happened?

exception message:

SymfonyComponentHttpKernelExceptionMethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: HEAD.
https://localhost/laravel-tester/public/ 

WelcomeController Method

public function index(){
   return view('welcome');
}

Advertisement

Answer

::get registers the route for methods GET and HEAD by default. You are trying to access it with a GET request (as you should) but it does not return it. Possibly there is something wrong with your Router class, so please check your RoutingRouter.php class against the method in the comment below. https://stackoverflow.com/a/22119028/10187949

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement