2014-08-29 15:08
浏览 72


I have a delete button used to delete a record like so

{{Form::open(array('method'=>'DELETE', 'route' => array('users.destroy', $user->id)))}}
{{Form::submit('Delete', array('class'=>'btn btn-danger'))}}

The form routes to the controller destroy function which I have like so

public function destroy($id)
  return Redirect::route('users.index');

But I want a confirmation alert to pop up before deleting the record. Is there a way for the controller to open a modal dialog and get the return value? or does the controller open a view that opens a modal that yet again directs to another controller that deletes or a controller that confused by how the controller is supposed to control the logic this way...

I have twitter bootstrap and jquery in my <head> section like so

<link href="//" rel="stylesheet">    |
<script src="//"></script>

图片转代码服务由CSDN问答提供 功能建议


 <  code> {{Form :: open(array('method'=&gt;'DELETE','route'=&gt; array('users.destroy',$ user-&gt; id)))}} 
 {{  Form :: submit('删除',数组('class'=&gt;'btn btn-danger'))}} 
 {{Form :: close()}} 
   \  n 


  public function destroy($ id)
 User :: find(  $ id) - &gt; delete(); 
返回Redirect :: route('users.index'); 

但我要确认 警报在删除记录之前弹出。 有没有办法让控制器打开模态对话框并获得返回值? 或者控制器是否打开一个视图,打开一个模态,然后再次指向另一个删除的控制器或一个重新路由的控制器...对控制器如何以这种方式控制逻辑感到困惑...... \ n

我的&lt; head&gt; 部分中有twitter bootstrap和jquery,如此

 &lt; link href =“//"rel =“stylesheet”&gt;  | 
&lt; script src =“//"></script>
  \  n 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douxiangshi6568 2014-08-29 15:33

    There is nothing you have to do with your controller, just some JavaScript will do the trick.

    Since you are using bootstrap the easiest way would be using BootstrapDialog.

    {{Form::open(array('method'=>'DELETE', 'route' => array('users.destroy', $user->id)))}}
    {{Form::submit('Delete', array('class'=>'btn btn-danger'))}}
            url = $(this).parent().attr('action');
            BootstrapDialog.confirm('Are you sure you want to delete?', function(result){
                if(result) {

    Note don't forget to add the following after Bootstrap and jQuery includes.

    <script src="your link to bootstrap-dialog.js"></script>

    You can download it from here.

    Working Demo

    打赏 评论

相关推荐 更多相似问题