Laravel 是否有从存储库设计模式恢复软删除记录的功能?

Laravel 是否有从存储库设计模式恢复软删除记录的功能?,laravel,restore,soft-delete,Laravel,Restore,Soft Delete,我在代码中使用了存储库设计模式,现在,我想恢复我的软删除记录。但我无法使用存储库设计模式来解决这个问题,我使用的是基于laravel的apiato框架。我想恢复我的任务记录 这是我的模型课 类属性扩展模型 { 使用软删除; } 这是我的删除存储代码 类DeletePropertyTask扩展任务 { 受保护的存储库; 公共函数构造(PropertyRepository$repository) { $this->repository=$repository; } 公共功能运行($id) { 试一

我在代码中使用了存储库设计模式,现在,我想恢复我的软删除记录。但我无法使用存储库设计模式来解决这个问题,我使用的是基于laravel的apiato框架。我想恢复我的任务记录

这是我的模型课

类属性扩展模型
{
使用软删除;
}
这是我的删除存储代码

类DeletePropertyTask扩展任务
{
受保护的存储库;
公共函数构造(PropertyRepository$repository)
{
$this->repository=$repository;
}
公共功能运行($id)
{
试一试{
$result=$this->repository->delete($id);
返回$result;
}
捕获(例外$e){
抛出新的DeleteResourceFailedException(null,null,null,null,$e);
}
}
}

Eloquent有一种使用
restore()
函数还原软删除条目的方法。这是更多信息的链接。

Eloquent有一种使用
restore()
函数还原软删除条目的方法。以下是有关详细信息的链接。

如果要还原软删除记录,可以使用restore()属性

public function restore($id)
{
    $this->repository->find($id)->restore();
}

如果要还原软删除记录,可以使用restore()属性

public function restore($id)
{
    $this->repository->find($id)->restore();
}

我找到了解决办法。在apiato存储库类中,有一个方法名
makeModel()
当你调用这个方法时,所有的东西都变成了雄辩的函数。之后,您可以使用
withTrash
方法在软删除记录之间进行搜索,并在调用
restore()
方法之后找到所需的特定记录

$this->repository->makeModel()->withTrash()->where('id',$property_id')->first()->restore();

我找到了解决方案。在apiato存储库类中,有一个方法名
makeModel()
当你调用这个方法时,所有的东西都变成了雄辩的函数。之后,您可以使用
withTrash
方法在软删除记录之间进行搜索,并在调用
restore()
方法之后找到所需的特定记录

$this->repository->makeModel()->withTrash()->where('id',$property_id')->first()->restore();

从任务中恢复软删除记录

$this->repository::withTrashed()->findorfail($id)->restore();

从任务还原软删除记录的步骤

$this->repository::withTrashed()->findorfail($id)->restore();

apiato存储库类不同于雄辩的,并且不存在一些方法。这不是很好,它不是
withTrash()
,而是
withTrashed()
小心拼写方法。apiato存储库类不同于eloquent,并且不存在某些方法。这不是很好,它不是
withTrash()
,而是
withTrashed()
注意方法的拼写。在apiato repository类中,如果记录被软删除,则不返回简单查找。并且应该使用withTrash方法,withTrash方法也不存在。在apiato存储库类中,如果记录被软删除,则不返回简单查找。并且应该使用withTrash方法,即withTrash方法也不存在。