簡體   English   中英

帶有甜蜜警報會話循環的Laravel會話

[英]Laravel sessions with sweet alert Session Loops

我只是對我的代碼感到困惑。 但是我真的認為我的代碼是正確的。 我正在嘗試在Laravel 5.1中使用with()方法,然后返回視圖,然后,如果存在已設置的會話,則會顯示甜蜜警報。 請在下面查看我的代碼:

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

我只希望它出現一次,但是如果我嘗試單擊“后退”按鈕,則會再次出現該消息。 我也嘗試過ff。 代碼,但沒有改變:

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

這里幫不上忙嗎?

Flash消息必須觸發,否則將無濟於事,因為您每次都需要為視圖設置它

但是,無論觸發器位於何處,都可以使用此代碼

請注意:-我只是每次都在嘗試

Route::get('/', function () {
    session()->flash('testing', 'I see this'); // Please have this line inside the trigger so the session does not get created everytime the view is called
    return view('welcome');
});

希望這可以幫助

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM