| 12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- <?php
- namespace App\Module\Farm\AdminControllers\Actions;
- use App\Module\Farm\Models\FarmSeedOutput;
- use Dcat\Admin\Grid\RowAction;
- use Illuminate\Http\Request;
- class CopyAction extends RowAction
- {
- protected $title = '复制';
- public function title()
- {
- return $this->title;
- }
- public function handle(Request $request)
- {
- try {
- $id = $this->getKey();
-
- // 查找原始记录
- $original = FarmSeedOutput::findOrFail($id);
-
- // 创建新记录
- $new = $original->replicate();
- $new->save();
-
- return $this->response()
- ->success("复制成功 [ID: {$new->id}]")
- ->refresh();
- } catch (\Exception $e) {
- return $this->response()
- ->error('复制失败: '.$e->getMessage());
- }
- }
- public function confirm()
- {
- return ['确定要复制此种子产出配置吗?', '复制操作将创建一个新的种子产出配置记录'];
- }
- }
|