首页 文章

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException没有消息

提问于
浏览
0

提交表格时,以下路线工作正常

Route::put('/autorisation', 'AdministratifController@update_autorisation')->name('administartif.updateautorisation');

但我想知道为什么当我试图访问 http://example.com/autorisation 它抛出

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

找不到页面

它's not about the form it' s关于进入浏览器并键入 example.com/autorisation 然后你得到 no message 的错误代替404

PS:在我的路线中我没有定义这个 Route::get('/autorisation')

4 回答

  • 0

    您将路线定义为 PUT ,但您尝试使用它像 GET 路线 . 这就是你得到 MethodNotAllowed 的原因 .

    如果你想显示404错误而不是这个MethodNotAllowed(当 DEBUG=false 时它会是一个Whoops)你应该在你的处理程序中处理它 .

    App\Exceptions\Handler 编辑 report 方法如下所示:

    public function report(Exception $exception)
    {
        if ($exception instanceof MethodNotAllowedHttpException) {
            abort(404, 'Page not found');
        }
    
        return parent::report($exception);
    }
    
  • 0

    请改变你的路线,试试这个:

    Route::post('autorisation', 'AdministratifController@update_autorisation')->name('administartif.updateautorisation');
    
  • 0

    通过自己访问页面,您可以执行GET HTTP请求而不是PUT .

  • 0

    您需要将路由设置为GET而不是PUT .

相关问题