DuplicateChestContentAction.php 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers\Actions;
  3. use App\Module\GameItems\Models\ItemChestContent;
  4. use Dcat\Admin\Grid\RowAction;
  5. use Illuminate\Http\Request;
  6. class DuplicateChestContentAction extends RowAction
  7. {
  8. protected $title = '复制';
  9. public function title()
  10. {
  11. return $this->title;
  12. }
  13. public function handle(Request $request)
  14. {
  15. try {
  16. $id = $this->getKey();
  17. // 查找原始记录
  18. $original = ItemChestContent::findOrFail($id);
  19. // 创建新记录
  20. $new = $original->replicate();
  21. $new->save();
  22. return $this->response()
  23. ->success("复制成功 [ID: {$new->id}]")
  24. ->refresh();
  25. } catch (\Exception $e) {
  26. return $this->response()
  27. ->error('复制失败: '.$e->getMessage());
  28. }
  29. }
  30. public function confirm()
  31. {
  32. return ['确定要复制此宝箱内容吗?', '复制操作将创建一个新的宝箱内容记录'];
  33. }
  34. }