简体   繁体   English

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

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

I have an Online Store project written in Laravel 5.8 and in this project, I have set some sessions at the Controller, like this:我有一个用 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','...')'

And the problem is, whenever the conflicting re-submits at checkout.blade.php , those session that were added before, still gets submitted.问题是,每当在checkout.blade.php重新提交conflicting时,之前添加的那些 session 仍然会被提交。 However, it should not submit the OLD session.但是,它不应提交 OLD session。

So how to do this with Laravel?那么如何用 Laravel 做到这一点呢?

I would really appreciate any idea or suggestion from you guy..我真的很感激你的任何想法或建议..

Thanks谢谢

You have to unset the session variables after one attempt like this像这样尝试一次后,您必须取消设置 session 变量

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

and for multiple data you can:对于多个数据,您可以:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM