【发布时间】:2021-01-25 22:04:13
【问题描述】:
我正在使用 laravel 7.x。
因为function(){return view(welcome);}在运行php artisan route:cache时会产生错误,所以我在下面写了这段代码来替换function():
Route::get('/', 'WelcomeController@index')->name('welcome');
它在php artisan serve 命令上运行良好。
但是当我直接从public 文件夹运行时,它会产生异常MethodNotAllowedHttpException。我找不到为什么会这样,你能帮我看看为什么会这样吗?
异常信息:
Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException
The GET method is not supported for this route. Supported methods: HEAD.
https://localhost/laravel-tester/public/
WelcomeController 方法
public function index(){
return view('welcome');
}
【问题讨论】:
-
运行
php artisan route:clear并重试。 -
谢谢,我开始了解它是如何返回错误的。您的解决方案正在运行,但是在缓存路由时仍然会出错。我将尝试再次查看 route.php 以找出它出错的原因。
-
这能回答你的问题吗? Laravel - Routes GET|HEAD