octobercms - 如何在 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>
解决方案
我解决了。在我的 onDelete 函数中,我应该使用这个“post('id')”而不是“$id”。
function onDelete(){
$model = Accounts::where('id', post('id'))->first()->delete();
}
推荐阅读
- android - Android:除非您添加意图过滤器,否则电子邮件意图 ACTION_SENDTO 不起作用
- flutter - Flutter:如何在中心对齐一个小部件,在底部对齐一些小部件
- git - 如何将 JIRA 查询与 Git Flow 关联起来
- c++ - 使用类在 C++ 中出现错误的最年轻的学生信息
- excel - 使用 RegEx 的 Powerpoint vba 宏
- blockchain - 创建一个可以进行交易的冷多币钱包
- laravel - GraphQL - Laravel - 默认为 OrderBy
- r - 如何删除达到特定值的多个数据框的行?
- python - ValueError:形状不匹配:形状的值数组无法广播到形状的索引结果
- selenium - 从网格执行测试用例时出现 org.openqa.selenium.SessionNotCreatedException 错误,描述中给出了整个错误