Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/powershell/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在Laravel 6中防止get/post冲突?_Php_Laravel - Fatal编程技术网

Php 如何在Laravel 6中防止get/post冲突?

Php 如何在Laravel 6中防止get/post冲突?,php,laravel,Php,Laravel,目前,我正在进行一个项目,我在其中创建了它,这样当用户在表单字段中键入正确的密码时,它将为他们提供给定部分中的项目 我面临的主要问题是,要做到这一点,我需要捕获请求,因此路由必须是post方法,而不是get方法: public function index(Request $request) { $id = $request->input('id'); $password = $request->input('password');

目前,我正在进行一个项目,我在其中创建了它,这样当用户在表单字段中键入正确的密码时,它将为他们提供给定部分中的项目

我面临的主要问题是,要做到这一点,我需要捕获请求,因此路由必须是post方法,而不是get方法:

    public function index(Request $request)
    {

        $id = $request->input('id');
        $password = $request->input('password');
        $result = DB::table('scrumboards')->find($id);

        if ($result->key == $password) {
            $scrumboard = $result;
            $items = DB::table('backlogs')->get();
            return view('scrumboard', ['items' => $items, 'scrumboard' => $scrumboard]);
        } else {
            $scrumboard = $result;
            return redirect('home');
        }
    }
路线如下:

Route::post('/scrumboard', 'ScrumboardController@index');
通过这样做,请求错误将不起作用,因为它希望重定向回,但无法,因为这是一个post方法


有什么办法可以避免这种冲突吗?

路由可以有多个HTTP谓词。将您的路线定义为

Route::match(['get', 'post'], '/scrumboard', 'ScrumboardController@index');

使其作为GET和POST路由可用。

路由可以有多个HTTP谓词。将您的路线定义为

Route::match(['get', 'post'], '/scrumboard', 'ScrumboardController@index');

使其成为获取和发布路由。

您是否使用axios在前端和后端之间进行异步数据流?是否使用axios在前端和后端之间进行异步数据流?