update
This commit is contained in:
@@ -97,8 +97,8 @@ abstract class Service
|
||||
*/
|
||||
public function list(array $params = []): array
|
||||
{
|
||||
$model = $this->repository->getQuery();
|
||||
$query = $model->newQuery();
|
||||
$model = $this->repository->getModel();
|
||||
$query = $this->repository->getQuery();
|
||||
|
||||
// 通过模型配置自动应用所有搜索条件
|
||||
$this->applySearch($query, $params);
|
||||
@@ -149,8 +149,7 @@ abstract class Service
|
||||
*/
|
||||
public function update(int $id, array $data): bool
|
||||
{
|
||||
$model = $this->repository->getQuery();
|
||||
$resource = $model->findById($id);
|
||||
$resource = $this->findById($id);
|
||||
$this->checkResourceExists($resource);
|
||||
|
||||
// 数据验证
|
||||
@@ -169,8 +168,7 @@ abstract class Service
|
||||
*/
|
||||
public function delete(int $id): bool
|
||||
{
|
||||
$model = $this->repository->getQuery();
|
||||
$resource = $model->findById($id);
|
||||
$resource = $this->findById($id);
|
||||
|
||||
$this->checkResourceExists($resource);
|
||||
|
||||
@@ -186,9 +184,8 @@ abstract class Service
|
||||
*/
|
||||
public function restore(int $id): bool
|
||||
{
|
||||
$model = $this->repository->getQuery();
|
||||
// 必须使用withTrashed()才能查询到已删除记录
|
||||
$resource = $model->withTrashed()->find($id);
|
||||
$resource = $this->repository->getQuery()->withTrashed()->find($id);
|
||||
$this->checkResourceExists($resource, '恢复的资源不存在');
|
||||
|
||||
$result = $this->repository->getQuery()->withTrashed()
|
||||
@@ -206,8 +203,7 @@ abstract class Service
|
||||
throw new BusinessException('请选择要删除的记录', 400);
|
||||
}
|
||||
|
||||
$model = $this->repository->getQuery();
|
||||
$exists = $model->whereIn('id', $ids)->exists();
|
||||
$exists = $this->repository->getQuery()->whereIn('id', $ids)->exists();
|
||||
if (! $exists) {
|
||||
throw new BusinessException('部分记录不存在', 404);
|
||||
}
|
||||
@@ -228,8 +224,8 @@ abstract class Service
|
||||
throw new BusinessException('请选择要恢复的记录', 400);
|
||||
}
|
||||
|
||||
$model = $this->repository->getQuery();
|
||||
$exists = $model->withTrashed()
|
||||
$exists = $this->repository->getQuery()
|
||||
->withTrashed()
|
||||
->whereIn('id', $ids)
|
||||
->whereNotNull('deleted_at')
|
||||
->exists();
|
||||
@@ -251,8 +247,7 @@ abstract class Service
|
||||
*/
|
||||
public function forceDelete(int $id): bool
|
||||
{
|
||||
$model = $this->repository->getQuery();
|
||||
$resource = $model->withTrashed()->find($id);
|
||||
$resource = $this->repository->getQuery()->withTrashed()->find($id);
|
||||
$this->checkResourceExists($resource, '要删除的资源不存在');
|
||||
|
||||
$result = $this->repository->getQuery()->withTrashed()
|
||||
|
||||
Reference in New Issue
Block a user