From 18eb1e91e738ed1d9cb98790a9fa781819059d3a Mon Sep 17 00:00:00 2001 From: zj Date: Thu, 30 Jul 2026 15:07:45 +0800 Subject: [PATCH] update --- src/Service.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/Service.php b/src/Service.php index 049856a..c5ffda4 100644 --- a/src/Service.php +++ b/src/Service.php @@ -26,6 +26,7 @@ use Hyperf\DbConnection\Db; */ abstract class Service { + protected ?Validator $validator = null; protected array $search = []; protected array $ignoreSearchFields = []; @@ -50,7 +51,7 @@ abstract class Service */ public function create(array $data): mixed { - $this->validator->scene('create', $data)->check(); + $this->validator?->scene('create', $data)->check(); return $this->repository->create($data); } @@ -59,7 +60,7 @@ abstract class Service */ public function save(array $data): mixed { - $this->validator->scene('create', $data)->check(); + $this->validator?->scene('create', $data)->check(); return $this->create($data); } @@ -69,7 +70,7 @@ abstract class Service public function updateById(mixed $id, array $data): mixed { // 数据验证 - $this->validator->scene('update', $data)->check(); + $this->validator?->scene('update', $data)->check(); return $this->repository->updateById($id, $data); } @@ -153,7 +154,7 @@ abstract class Service $this->checkResourceExists($resource); // 数据验证 - $this->validator->scene('update', $data)->check(); + $this->validator?->scene('update', $data)->check(); // 钩子:处理更新时的特殊逻辑(如禁止自身为父级) $this->handleUpdateSpecialLogic($id, $data);