简体   繁体   English

会话忘记似乎不适用于 Laravel 5.8

[英]Session forget does not seem to be working with Laravel 5.8

I have submitted a session called payment at the Controller:我在 Controller 提交了一个名为payment的会话:

try {
   if ($request->pay_wallet == '1') {
      Session::put('wallet', 'payment');
      return redirect()->back();
   }
}catch (\Exception $e) {
   dd($e);
}

Then at the View, I tried this:然后在视图中,我尝试了这个:

@php
if(session('wallet')){
    $us_id = Auth()->user()->usr_id;
    $user_wallet = App\UserWallet::where('user_id', $us_id)->get();
    foreach($user_wallet as $uw){
        echo "
        <ul>
            <li>$uw->id</li>
            <li>$uw->balance</li>
        </ul>
        ";
    }
    Session::forget('wallet');
}
@endphp

But the problem is, after redirecting page, the session wallet is still alive.但问题是,重定向页面后,会话wallet仍然存在。

So how to kill the session properly after the foreach at View?那么如何在 View 的foreach之后正确foreach会话呢?

Below will remove session key temporarily.下面将暂时删除会话密钥。

Session::forget('wallet');

To remove it permanently also use this line:要永久删除它,也可以使用以下行:

Session::save();

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

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