octobercmsoctobercms-pluginsoctobercms-backendoctober-form-controller

How to delete a table row from the frontend in octobercms


I need some help. I want to create a delete function on the frontend page, that When clicked, it will delete that row on the table. i have try it his try and nothing work for me. Here is my code

 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> 

Solution

  • i solved it. In my onDelete function i should use this " post('id')" instead of "$id".

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