Laravel 5.8: 你能帮我解决这个关于会话的问题吗

Laravel 5.8: Can you help me with this problem about sessions

我有一个用 Laravel 5.8 编写的在线商店项目,在这个项目中,我在控制器上设置了一些会话,如下所示:

    $delivery_types = [];
    $conflicting = false;

    if ($foundOrder != null) {
        foreach ($foundOrder as $key => $value) {
            $product = Product::with('uploaded')->wherePrdId($value->id)->select('*')->first();

            array_push($delivery_types, $product->prd_delivery);

            $prds[] = [
                $product,
                $value->quantity,
                $value->price
            ];
        }

        $delivery_types = array_unique($delivery_types);

        if (in_array('iran_free_delivery', $delivery_types) && in_array('tehran_free_delivery', $delivery_types)) {
            $conflicting = true;
        }

        if (in_array(null, $delivery_types)) {
            Session::put('free' , 'no');
        } else if (in_array('iran_free_delivery', $delivery_types) && in_array('tehran_free_delivery', $delivery_types)) {
            Session::put('free' , 'city_country');
            //Session::put('iran' , '10');
            //Session::put('free_notfree' , '13');
        } else if (in_array('iran_free_delivery', $delivery_types)) {
            Session::put('free' , 'country');
        } else if (in_array('tehran_free_delivery', $delivery_types)) {
            Session::put('free' , 'city');
        } else {
            Session::put('free' , '0');
        }

    } else {
        $prds = [];
    }
    ...

 return view('frontend.shop.carts.index', compact('conflicting','...')'

问题是,每当 conflicting 重新提交时 checkout.blade.php,之前添加的那些会话仍然会被提交。 但是,它不应提交旧会话。

那么如何用 Laravel 做到这一点?

非常感谢你的任何想法或建议..

谢谢

像这样尝试一次后,您必须取消设置会话变量

$this->session->unset_userdata('name');

对于多个数据,您可以:

$array_name = array('username' => '', 'email' => '');

$this->session->unset_userdata($array_name);