You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
aquaculture/app/Admin/Actions/Post/ForceDeleteProductAction.php

46 lines
1.3 KiB

<?php
namespace App\Admin\Actions\Post;
use App\Models\Product;
use Encore\Admin\Actions\RowAction;
use Illuminate\Http\Request;
class ForceDeleteProductAction extends RowAction
{
// 动作名称,显示在界面上的按钮文本
public $name = '删除';
/**
* 处理强制删除产品的逻辑
*
* @param Product $product 被删除的产品模型
* @return \Encore\Admin\Actions\Response 返回操作结果的响应
*/
public function handle(Product $product)
{
// 调用模型的 forceDelete 方法,永久删除产品
$product->forceDelete();
// 返回成功响应并刷新页面
return $this->response()->success('操作成功.')->refresh();
}
/**
* 从请求中检索产品模型
*
* @param Request $request 当前请求实例
* @return Product|false 返回找到的产品模型或 false
*/
public function retrieveModel(Request $request)
{
// 从请求中获取 '_key' 参数
if (!$key = $request->get('_key')) {
return false; // 如果没有找到 '_key',返回 false
}
// 使用 withTrashed 方法查询包括已删除的产品,并根据找到的键查找产品
return Product::query()->withTrashed()->findOrFail($key);
}
}