Laravel sessions with sweet alert Session Loops

Viewed 2149

I'm just confused about my code. But I really thought that my code is correct. I'm trying to use with() method in Laravel 5.1 and then return to a view, then the sweet alert appears if the session that has been set is exists. Please see my code below:

PageController.php

return redirect()->route('list.view')->with('sweetalert', 'List has been created!');

view.blade.php

@extends('layout.master')

@section('container')
  @foreach($lists as $list)
    <li>{{ $list->name }}</li>
  @endforeach
@stop

master.blade.php

<div class="container">
  // some markup here...
</div>

@if(Session::has('sweetalert'))
<script>
    swal('Success!', '{{ Session::get('sweetalert') }}', 'success');
</script>
@endif

I only want it to appear once, but if I try to click the back button, the message appears again. I have also tried the ff. code but nothings change:

@if(Session::has('sweet'))
  <script>
      swal('Success!', '{{ Session::get('sweetalert') }}', 'success');
  </script>
  <?php Session::forget('sweetalert'); ?>
@endif

Little help here?

1 Answers
Related