删
<h2><strong>删除按钮</strong></h2>
<ul>
<li>控制器中的 <code>list</code> 方法负责构建数据列表</li>
</ul>
<pre><code class="language-php">public function list()
{
$crud = $this-&gt;baseCRUD()
// 配置 CRUD 组件的批量操作
-&gt;bulkActions([
$this-&gt;bulkDeleteButton() // 批量删除按钮
// 批量删除按钮会携带选中的主键字段, 发起 ajax 请求, 实现删除功能
])
-&gt;columns([
amis()-&gt;TableColumn()-&gt;label('ID')-&gt;name('id')-&gt;sortable(),
// ...
// 这里是列表的行内操作按钮
$this-&gt;rowActions([
$this-&gt;rowEditButton(true), // 编辑按钮
$this-&gt;rowDeleteButton(), // 删除按钮
// 删除按钮会携带主键字段, 发起 ajax 请求, 实现删除功能
]),
]);
return $this-&gt;baseList($crud);
}</code></pre>
<p><br></p>
<h2><strong>删除逻辑</strong></h2>
<ul>
<li>通过列表上的操作按钮, 请求到 <code>AdminController</code> 中的 <code>destroy</code> 方法, 实现删除功能</li>
<li>如果有自定义删除逻辑的需求, 可以在对应的 <code>service</code> 中, 重写 <code>delete</code> 方法</li>
</ul>
<pre><code class="language-php">/**
* 删除
*
* @param $ids
*
* @return JsonResponse|JsonResource
*/
public function destroy($ids)
{
$rows = $this-&gt;service-&gt;delete($ids);
return $this-&gt;autoResponse($rows, __('admin.delete'));
}
/**
* service 中实际处理删除逻辑的方法, 可以在自己的 service 中重写该方法
*
* @param string $ids
*
* @return mixed
*/
public function delete(string $ids): mixed
{
return $this-&gt;query()-&gt;whereIn($this-&gt;primaryKey(), explode(',', $ids))-&gt;delete();
}</code></pre>