Ver código fonte

修复Validator使用方式:解决验证器找不到的问题

- 修复PetGetValidation中PetGetValidator的使用方式,从类名字符串改为实例化对象
- 修复FertilizerValidation中所有Validator的使用方式,统一使用new实例化
- 解决Pet/GetHandler中'The validator don't exists'错误
- 确保验证框架能够正确识别和调用自定义Validator
- 提高系统稳定性和验证逻辑的可靠性
notfff 7 meses atrás
pai
commit
520d28026f

+ 4 - 4
app/Module/Farm/Validations/FertilizerValidation.php

@@ -45,22 +45,22 @@ class FertilizerValidation extends ValidationCore
             ],
             // 验证土地是否属于用户
             [
-                'land_id', LandOwnershipValidator::class, 'args' => ['user_id', 'land'],
+                'land_id', new LandOwnershipValidator($this, ['user_id', 'land']),
                 'msg' => '土地不存在或不属于当前用户'
             ],
             // 验证用户是否拥有该物品
             [
-                'item_id', ItemOwnershipValidator::class, 'args' => ['user_id', 'instance_id', 'quantity'],
+                'item_id', new ItemOwnershipValidator($this, ['user_id', 'instance_id', 'quantity']),
                 'msg' => '您没有该肥料物品'
             ],
             // 验证物品是否为肥料类型
             [
-                'item_id', FertilizerItemValidator::class, 'args' => ['fertilizer_item', 'crop_growth_time'],
+                'item_id', new FertilizerItemValidator($this, ['fertilizer_item', 'crop_growth_time']),
                 'msg' => '该物品不是有效的肥料'
             ],
             // 验证是否可以使用肥料
             [
-                'land_id', FertilizerUsageValidator::class, 'args' => ['land', 'crop'],
+                'land_id', new FertilizerUsageValidator($this, ['land', 'crop']),
                 'msg' => '当前土地状态或作物生长阶段不允许使用肥料'
             ]
         ];

+ 1 - 1
app/Module/Pet/Validations/PetGetValidation.php

@@ -30,7 +30,7 @@ class PetGetValidation extends ValidationCore
             ],
             // 验证宠物获取相关逻辑
             [
-                'item_id', PetGetValidator::class, 'args' => ['user_id'],
+                'item_id', new PetGetValidator($this, ['user_id']),
                 'msg' => '宠物获取验证失败'
             ]
         ];