| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 |
- <?php
- namespace App\Module\Cleanup\AdminControllers\Actions;
- use Dcat\Admin\Grid\BatchAction;
- use Dcat\Admin\Actions\Response;
- use Illuminate\Http\Request;
- use Illuminate\Database\Eloquent\Collection;
- /**
- * 批量启用Action
- *
- * 用于批量启用清理配置
- */
- class BatchEnableAction extends BatchAction
- {
- /**
- * 按钮标题
- */
- protected $title = '批量启用';
- /**
- * 处理请求
- */
- public function handle(Request $request)
- {
- try {
- // 获取选中的ID
- $ids = $this->getKey();
-
- if (empty($ids)) {
- return $this->response()->error('请选择要启用的配置');
- }
-
- // 批量更新
- $count = $this->getModel()::whereIn('id', $ids)->update(['is_enabled' => 1]);
-
- return $this->response()
- ->success("成功启用 {$count} 个配置")
- ->refresh();
-
- } catch (\Exception $e) {
- return $this->response()
- ->error('批量启用失败:' . $e->getMessage());
- }
- }
- /**
- * 确认对话框
- */
- public function confirm()
- {
- return [
- '确认批量启用?',
- '此操作将启用选中的所有清理配置。'
- ];
- }
- }
|