BatchEnableAction.php 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. namespace App\Module\Cleanup\AdminControllers\Actions;
  3. use Dcat\Admin\Grid\BatchAction;
  4. use Dcat\Admin\Actions\Response;
  5. use Illuminate\Http\Request;
  6. use Illuminate\Database\Eloquent\Collection;
  7. /**
  8. * 批量启用Action
  9. *
  10. * 用于批量启用清理配置
  11. */
  12. class BatchEnableAction extends BatchAction
  13. {
  14. /**
  15. * 按钮标题
  16. */
  17. protected $title = '批量启用';
  18. /**
  19. * 处理请求
  20. */
  21. public function handle(Request $request)
  22. {
  23. try {
  24. // 获取选中的ID
  25. $ids = $this->getKey();
  26. if (empty($ids)) {
  27. return $this->response()->error('请选择要启用的配置');
  28. }
  29. // 批量更新
  30. $count = $this->getModel()::whereIn('id', $ids)->update(['is_enabled' => 1]);
  31. return $this->response()
  32. ->success("成功启用 {$count} 个配置")
  33. ->refresh();
  34. } catch (\Exception $e) {
  35. return $this->response()
  36. ->error('批量启用失败:' . $e->getMessage());
  37. }
  38. }
  39. /**
  40. * 确认对话框
  41. */
  42. public function confirm()
  43. {
  44. return [
  45. '确认批量启用?',
  46. '此操作将启用选中的所有清理配置。'
  47. ];
  48. }
  49. }