0

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

    $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,之前添加的那些会话仍然会被提交。但是,它不应该提交 OLD 会话。

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

我真的很感激你的任何想法或建议..

谢谢

4

1 回答 1

0

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

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

对于多个数据,您可以:

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

$this->session->unset_userdata($array_name);
于 2021-07-17T10:37:25.510 回答