【问题标题】:Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException No messageSymfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException 无消息
【发布时间】:2018-03-25 14:37:12
【问题描述】:

当我提交表单时,以下路线工作正常

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

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

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException
No message

找不到页面插入

这不是关于表单,而是关于进入浏览器并输入example.com/autorisation,然后你会得到no message 的错误代替404

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

【问题讨论】:

  • 请在表格中检查您的方法
  • 我有 POST 问题,它不是关于表单的问题,它是关于进入浏览器并输入 example.com/autorisation 然后你得到那个错误而不是 404

标签: laravel routes


【解决方案1】:

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

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      您将路由定义为PUT,但您正尝试像GET 路由一样使用它。这就是您收到MethodNotAllowed 的原因。

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

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

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

      【讨论】:

        【解决方案4】:

        请更改您的路线并尝试以下操作:

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

        【讨论】:

          猜你喜欢
          • 2018-06-21
          • 1970-01-01
          • 2019-04-11
          • 2020-01-01
          • 1970-01-01
          • 2020-06-22
          • 2014-11-20
          • 2019-07-01
          • 2018-09-06
          相关资源
          最近更新 更多