0

i'm using session for display messages in laravel. my controller code is:

return redirect()->route('abc')->with('success','data save successfully');

and for show messages i'm using following code:

@if ($message = Session::get('success'))
    <div class="alert alert-success alert-block">
        <button type="button" class="close" data-dismiss="alert">×</button> 
            <strong>{{ $message }}</strong>
    </div>
@end if

after i'm redirect to another route and back again then previous page so message display again. if i'm using session::forget('success') so session message not display.

vicky793
  • 431
  • 1
  • 3
  • 17
  • Try this: https://stackoverflow.com/a/21004425/5192105 – Sachin Bahukhandi May 01 '20 at 18:06
  • This is a normal action from the browsers. When you back to last page, the browser show last state and does not load new state. – elyas.m May 01 '20 at 18:11
  • @elyas.m so how to disappear my message when i am back to last page? any solution? – vicky793 May 01 '20 at 18:16
  • I think it's not a bug. but you can provide back button in your blade as a link to previous page or force reload previous page by javascript. but I don't know these ways are standard or efficient! – elyas.m May 01 '20 at 18:28

2 Answers2

0

Try using Session::pull('success') or Session::has('success') in blade instead of get()

You can check more about session Here

Nazem Mahmud Piash
  • 1,053
  • 1
  • 13
  • 34
-1

When you press the back button, the browser shows the cached version of that page. In this case you need to reload the page.

Use the following script to force reload the page if user press back button.

if(performance.navigation.type == 2){
    location.reload();
}

Note: No need to clear the session.

Mahmudur Rahman
  • 745
  • 5
  • 13