【问题标题】:Why Home route not works in production - laravel?为什么家庭路线在生产中不起作用 - laravel?
【发布时间】:2021-09-21 14:06:24
【问题描述】:

作曲家更新后,主路由 (/) 在实时服务器中不起作用

它正在显示:

方法不允许 此 URL 不允许请求的方法 GET。

此外,在执行过程中遇到了 405 Method Not Allowed 错误 尝试使用 ErrorDocument 来处理请求。

Route: 
Route::post('/', [WebController::class, 'index']);

除此之外的所有路由都可以在实时服务器中使用

【问题讨论】:

  • 首页路由的请求类型应该是“GET”而不是“POST”。

标签: php laravel


【解决方案1】:

请将post改为get

Route: Route::post('/', [WebController::class, 'index']);

Route: Route::get('/', [WebController::class, 'index']);

你的错误是HTTP request methods

【讨论】:

    【解决方案2】:

    改变

    Route::post('/', [WebController::class, 'index']);
    

    Route::get('/', [WebController::class, 'index']);
    

    如果您确定index 不是您将向其发布数据的路线,否则您可能需要清除缓存:

    php artisan route:cache
    

    【讨论】:

      【解决方案3】:

      GET 请求使用 index 方法,POST 请求使用 Store 方法,PUT 请求使用 Update 方法,DELETE 使用 destroy 方法。

      你可以使用常用的方法,

      Route::resource('/', WebController::class); // resource route
      

      这样您就可以避免提及每个请求的方法名称。

      【讨论】:

        【解决方案4】:

        使用获取:

        Route::get('/', [WebController::class, 'index']);
        

        如果 index 是控制器中的唯一方法,则更方便地使用可调用控制器:

        php artisan make:controller WebController --invokable
        
        Route::get('/', WebController::class);
        

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2016-10-05
          • 2019-12-04
          • 1970-01-01
          • 1970-01-01
          • 2021-08-14
          • 2014-11-21
          • 1970-01-01
          • 1970-01-01
          相关资源
          最近更新 更多