I have a blade file thanks.blade.php where I put two sessions grand_total and order_id. When I refresh the page session still exists.
I want when I refresh the page the session should be destroyed. I have written the session forget code at the end. Is it correct? I think it’s not correct then how to write it.
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta name="description" content=""> <meta name="author" content=""> <title>Thanks</title> <link href="{{ url('css/front_css/bootstrap.min.css') }}" rel="stylesheet"> <link href="{{ url('css/front_css/font-awesome.min.css') }}" rel="stylesheet"> <link href="{{ url('css/front_css/prettyPhoto.css') }}" rel="stylesheet"> <link href="{{ url('css/front_css/price-range.css') }}" rel="stylesheet"> <link href="{{ url('css/front_css/animate.css') }}" rel="stylesheet"> <link href="{{ url('css/front_css/main.css') }}" rel="stylesheet"> <link href="{{ url('css/front_css/responsive.css') }}" rel="stylesheet"> <!--[if lt IE 9]> <script src="{{ url('js/front_js/html5shiv.js') }}"></script> <script src="{{ url('js/front_js/respond.min.js') }}"></script> <![endif]--> <!-- favicon --> <link rel="icon" type="image/png" sizes="192x192" href="{{ asset('images/ico/android-icon-192x192.png')}}"> </head> <!--/head--> <body> <!-- Header Part --> @include('layouts.front_layout.front_header') <div class="jumbotron text-center"> <h1 class="display-3">Thank You!</h1> <p class="lead"><strong>Your Order Is Successfully Place</strong></p> <p class="lead">Your Order number is {{Session::get('order_id')}} and grand total is PK. {{Session::get('grand_total')}}</p> <hr> <p> <strong>Please check your email</strong> for further instruction. Having trouble? <a href="{{url('contactus')}}">Contact us</a> </p> <p class="lead"> <a class="btn btn-primary btn-sm" href="{{url('/')}}" role="button">Continue to homepage</a> </p> </div> <!--/Footer--> @include('layouts.front_layout.front_footer') <script src="{{ url('js/front_js/jquery.js') }}"></script> <script src="{{ url('js/front_js/bootstrap.min.js') }}"></script> <script src="{{ url('js/front_js/main.js') }}"></script> </body> </html> <php Session::forget('grand_total'); Session::forget('order_id'); ?>
Answers:
Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.
Method 1
You have to use following code below
@php IlluminateSupportFacadesSession::forget('grand_total'); IlluminateSupportFacadesSession::forget('order_id'); @endphp
It is working fine for me. I have just now used in my project.
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0