update
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user