重定向时显示的模态(Laravel)

时间:2017-11-16 22:01:18

标签: laravel bootstrap-modal

我正在尝试在重定向到页面时显示模式。

我正在关注此回复(Laravel how to redirect back to boostrap modal dialog window

我的控制器:

return redirect('postings')->with('welcome_msg');

我的观点

@if(Session::has('welcome_msg'))        
<script>
$(function() {
$('#myModal').modal('show');
});
</script>
@endif

<div class="modal fade" id="myModal role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    ...
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  </div>
</div>

但是,弹出窗口时不显示模态。我究竟做错了什么?

1 个答案:

答案 0 :(得分:1)

<div class="modal fade" id="myModal role="dialog" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content">
  <div class="modal-header">
    <h5 class="modal-title" id="exampleModalLabel">Modal title</h5>
    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
      <span aria-hidden="true">&times;</span>
    </button>
  </div>
  <div class="modal-body">
    ...
  </div>
  <div class="modal-footer">
    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
  </div>
</div>

@if(Session::has('welcome_msg'))        
<script>
$(function() {
$('#myModal').modal('show');
});
</script>
@endif

这可能会解决它。 HTML必须在javascript之前加载。