DuplicateRowAction.php 959 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. <?php
  2. namespace App\Module\GameItems\AdminControllers\Actions;
  3. use App\Module\GameItems\Repositorys\ItemRepository;
  4. use Dcat\Admin\Grid\RowAction;
  5. use Illuminate\Http\Request;
  6. class DuplicateRowAction 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. $repository = app(ItemRepository::class);
  18. $item = $repository->duplicate($id);
  19. return $this->response()
  20. ->success("复制成功 [ID: {$item->id}]")
  21. ->refresh();
  22. } catch (\Exception $e) {
  23. return $this->response()
  24. ->error('复制失败: '.$e->getMessage());
  25. }
  26. }
  27. public function confirm()
  28. {
  29. return ['确定要复制此物品吗?', '复制操作将创建一个新的物品记录'];
  30. }
  31. }