laravel,重定向后显示模式

时间:2018-12-21 11:29:33

标签: javascript jquery laravel

我试图在重定向后显示带有模式的信息。  这就是我要做的:

控制器:     返回redirect()-> route('verification',Auth :: user()-> id)-> with(['code',1]);

verification.blade.php

@if(!empty($code) && $code == 1)
    <script>
        $(function() {
            $('#myModal').modal('show');
        });
    </script>
@endif

    <div id="myModal" class="modal fade" style="display: none;">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal">×</button>
                                <h5 class="modal-title">example</h5>
                            </div>

                            <div class="modal-body">
                                <h6 class="text-semibold text-center">example</h6>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

重定向时,它仅沿路线行驶而未显示模式。 我该怎么办?

2 个答案:

答案 0 :(得分:1)

您可以尝试以下方法:

<div id="myModal" class="modal fade" style="{{Session::has("code") ? Session::get('code')==1 ? "display:block":"" : "display:none"}}">
                    <div class="modal-dialog modal-lg">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal">×</button>
                                <h5 class="modal-title">example</h5>
                            </div>

                            <div class="modal-body">
                                <h6 class="text-semibold text-center">example</h6>

                                <div class="modal-footer">
                                    <button type="button" class="btn btn-link" data-dismiss="modal">Close</button>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>

在尝试删除这些行之前:

@if(!empty($error_code) && $code == 1)
    <script>
        $(function() {
            $('#myModal').modal('show');
        });
    </script>
@endif

答案 1 :(得分:0)

我建议您使用会话:

// YOUR CODE HERE
session()->flash('code', $yourcodehere);
return redirect()->route('verification', Auth::user()->id);

在Verification.blade.php

// CHECK IF HAS SESSION 
@if (session()->has('code') && session()->get('code') == 1)
<script>
  $(document).ready(function(){
   $("#myModal").modal();
  }); 
</script>
@endif