如果请求未发布,则重定向到另一条路线

时间:2021-04-21 18:45:20

标签: laravel

 $checkMethod = $request->method();
        if (!$checkMethod) {
            return redirect('todo_show');
        } else {
            echo "yes";
        }

如果请求未发布,那么我如何重定向到另一条路线。发生此错误“此路由不支持 GET 方法。支持的方法:POST”。

1 个答案:

答案 0 :(得分:1)

将您的路线 Route::post... 更改为 Route::any...Route::match(['GET', 'POST')]… 根据 Laravel documentation,您可以在控制器上检查此请求方法:

$method = $request->method();
if ($request->isMethod('post')) {
    return redirect('todo_show');
} else {
    echo "yes";
}