首页 > 解决方案 > 如何在 octobercms 中从前端删除表格行

问题描述

我需要一些帮助。我想在前端页面上创建一个删除功能,单击该功能时,它将删除表格上的该行。我已经尝试过他的尝试,但对我没有任何帮助。这是我的代码

 function onDelete(){

         $model = Accounts::where('id', $id)->first()->delete();

 }     
    ```
      


here is the  twig

            
      
                     <tbody>
                             {% for log in logs %}
                                    <tr>
                                        <td>{{log.name}}</td>
                                        <td>{{log.account_no}}</td>
                                        <td>{{log.code}}</td>
                                       <td>  
                                            <button data-request="onDelete"
                                               data-request-data="id:{{ log.id }}"
                                                data-request-confirm="Are you sure ?"
                                               class="btn btn-sm btn-default">
                                                     delete
                                            </button> 
                                       </td>
                                        
                                    </tr>
                                    
                                  {% endfor %}
                            </tbody> 

标签: octobercmsoctobercms-pluginsoctobercms-backendoctober-form-controller

解决方案


我解决了。在我的 onDelete 函数中,我应该使用这个“post('id')”而不是“$id”。

 function onDelete(){

         $model = Accounts::where('id', post('id'))->first()->delete();

 }

推荐阅读