2016-07-01 117 views

回答

2

控制器的动作会是这样的..

//use Illuminate\Http\Request; 
    public function flashTest(Request $request){ 
    //see explanation for following line at very end 
    $request->session()->forget('flash_notification'); 

    //Flash::success('this is an alert message'); //if you want to show alert message 

    Flash::overlay('Modal Message'); 
    return view('yourview'); 
    } 

鉴于

<head> 
<!-- Bootstrap css--> 
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" rel="stylesheet"> 
<!-- jQuery --> 
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script> 
</head> 
<body> 

<!--if it's not an overlay, show flash message--> 
@if (!Session::has('flash_notification.overlay')) 
    <div class="alert alert-{{ Session::get('flash_notification.level') }}"> 
     <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button> 
     {{ Session::get('flash_notification.message') }} 
    </div> 
@else 

<!--perform your overlay action here. For now i am showing a model--> 
    <script type="text/javascript"> 
     $(document).ready(function(){ 
      $('#myModal').modal('show'); 
     }); 
    </script> 

    <!-- bootstrap Modal --> 
    <div id="myModal" class="modal fade" role="dialog"> 
     <div class="modal-dialog"> 
      <!-- Modal content--> 
      <div class="modal-content"> 
       <div class="modal-header"> 
        <button type="button" class="close" data-dismiss="modal">&times;</button> 
        <h4 class="modal-title">{{ Session::get('flash_notification.title') }}</h4> 
       </div> 
       <div class="modal-body"> 
        <p>{{ Session::get('flash_notification.message') }}</p> 
       </div> 
       <div class="modal-footer"> 
        <button type="button" class="btn btn-default" data-dismiss="modal">Close</button> 
       </div> 
      </div> 
     </div> 
    </div> 
    @endif 
    <!-- other code --> 

    <!-- bootstrap js --> 
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 
</body> 

OR

,如果你仅仅只想用这个包; 运行命令php artisan vendor:publish 在config/app.php中添加代码后,如laracast/flash中所述。

这将在“/ vendor/laracasts/flash/src/views /”目录中添加两个包视图。在这里您可以找到默认视图(您可以自定义它们)。

现在在你的视图文件只需添加

<body> 

@include('flash::message')<!-- this line is important --> 

<!-- bootstrap js --> 
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script> 

<!-- This is only necessary if you do Flash::overlay('...') --> 
<script> 
$('#flash-overlay-modal').modal(); 
</script> 
</body> 

解释$request->session()->forget('flash_notification');

不知这个包是保留覆盖会话变量的键。即如果您首先显示重叠信息并且下次要显示Flash信息,则Flash信息也会显示为重叠。此行被添加以防止这种行为。请参阅laravel session

也看看这个bootstrap overlay

+0

TY为你的答案,但我想'叠加'。使用提供的代码,仅显示闪烁警报。 –

+0

仍然无法正常工作。 –

+0

我已经测试过上面的代码,它的工作正常。向我们展示您的代码;你是如何做的,并提及是否有任何错误消息。 – SJB