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');
}
::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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.