Flash 消息保留在那里,无法自行关闭和按钮关闭。我使用 bootstrap 和 js 来构建 flash 消息。这是我的代码。
Controller ,我放在重定向行之前。
Session::flash('flash_message', 'It has been saved!');
另外,我在 Controller 上编写了use Session
。
我制作了 flash_message.blase.php
@if(Session::has('flash_message'))
<div class="alert alert-success {{ Session::has('penting') ? 'alert-important' : '' }}">
<button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
{{ Session::get('flash_message') }}
</div>
@endif
flash_message.blade.php 已收录到索引中。
这是js代码:
$('div.alert').not('.alert-important').delay(3000).slideUp(300);
js 代码已在我的主模板上编写为脚本。
为什么这些不起作用?如何解决?
最佳答案
试试这个
@if (session()->has('success'))
<div class="alert alert-dismissable alert-success">
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
<strong>
{!! session()->get('success') !!}
</strong>
</div>
@endif
关于javascript - Laravel flash 消息无法使用关闭按钮关闭并且暂时无法自行关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51296747/