0

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:

Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
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');
}
Herman
  • 67
  • 2
  • 5
  • 1
    run `php artisan route:clear` and try again. – zahid hasan emon Oct 11 '20 at 11:50
  • thank you, I started to understand how it return error. Your solution is working, but it's still give error when route is cached. I'll try to look at route.php again to figure out why it give error. – Herman Oct 11 '20 at 12:29
  • Does this answer your question? [Laravel - Routes GET|HEAD](https://stackoverflow.com/questions/22118598/laravel-routes-gethead) – Wesley Smith Oct 11 '20 at 20:22

1 Answers1

1

::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 Routing\Router.php class against the method in the comment below. https://stackoverflow.com/a/22119028/10187949

panjezor
  • 118
  • 8