Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to destroy session when clicks on browser's back button

I am flashing a success message using session->flash() method in laravel. But when user clicks back button the message comes up again. How to fix this. My code for showing message is -

@if(Session::get('success') )
    <script>
        swal({
            text: "{{Session::get('success')}}",
            button: localMsg.ok,

        }).then((isConfirm) => {
        });
    </script>
    @elseif(Session::get('error'))
    <script>
        swal({
            text: "{{Session::get('error')}}",
            button: localMsg.ok,

        }).then((isConfirm) => {
        });

    </script>
@endif
like image 794
Saher Siddiqui Avatar asked Jan 27 '26 19:01

Saher Siddiqui


1 Answers

You should destroy session values for success and error message

@if(Session::get('success') )
    <script>
        swal({
            text: "{{Session::get('success')}}",
            button: localMsg.ok,

        }).then((isConfirm) => {
        });
     {{ Session::forget('success'); }} //Add this line to destroy value for 'success'
    </script>
    @elseif(Session::get('error'))
    <script>
        swal({
            text: "{{Session::get('error')}}",
            button: localMsg.ok,

        }).then((isConfirm) => {
        });
     {{ Session::forget('error'); }} //Add this line to destroy value for 'error'
    </script>
@endif
like image 125
Harpal Singh Avatar answered Jan 29 '26 09:01

Harpal Singh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!