'require', 'name' => 'require|checkName', ]; /** * 参数描述 * @var string[] */ protected $field = [ 'id' => 'id', 'name' => '客户名称' ]; /** * @notes 添加场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneAdd() { return $this->remove('id', true); } /** * @notes 编辑场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneEdit() { return $this->only(['id', 'name']); } /** * @notes 删除场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneDelete() { return $this->only(['id']); } /** * @notes 详情场景 * @return CustomValidate * @author likeadmin * @date 2023/11/11 22:10 */ public function sceneDetail() { return $this->only(['id']); } public function checkName($value, $rule, $data) { if (!empty($data['id'])) { $custom = Custom::where('name', $value)->where('id', '<>', $data['id'])->findOrEmpty(); } else { $custom = Custom::where('name', $value)->findOrEmpty(); } if (!$custom->isEmpty()) { return '客户已存在!'; } return true; } }