[英]How to delete a record in octobercms?
我有點困惑它是如何組合在一起的。 我正在嘗試從記錄列表中刪除一條記錄,而我目前正在使用它。
function onDelete()
{
$recordId = post('record')
$record = Advert::find($recordId);
$record->delete();
}
我在樹枝上
<tbody>
{% for post in posts %}
<td><a href="{{ 'product-single'|page({ slug: post.slug }) }}" name = "record">{{ post.title }}</a></td>
<td><button class="btn btn-sm btn-danger" data-request ="onDelete" data-request-confirm="Are you sure" data-request-success="alert('Successfully Deleted')">Delete</button> </td>
</tr>
{% endfor %}
</tbody>
我目前有此錯誤
“調用成員函數delete()時為null”
您沒有在AJAX請求中將記錄ID發送到服務器。
將data-request-data="record: {{ post.id }}"
到觸發AJAX請求的button
,以便post('record')
實際上從AJAX請求中獲取數據,該數據可用於查找該記錄。您要刪除。
確保在查詢時使用字段名稱。 嘗試這個。
function onDelete()
{
$recordId = request('post')
Advert::where('slug',$recordId)->delete();
}
如果沒有,請添加die()並使用print_r檢查Advert :: where是否返回任何對象。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.