【发布时间】:2017-12-15 06:07:41
【问题描述】:
我想知道为什么我无法在 laravel 中恢复软删除的数据。我所做的一切都是正确的,但不确定我缺少什么,所以我无法恢复数据。
我的模特是
namespace App\Model\Clients;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
class SocialAccounts extends Model{
protected $table = 'social_accounts';
use SoftDeletes;
protected $dates = ['deleted_at'];
}
我使用了软删除特征。为了恢复我的软删除数据,我正在做类似下面的事情
$restoreAccount = SocialAccounts::withTrashed()->find($id)->restore();
但它不会恢复数据,我假设当我们恢复数据时 laravel NULL 删除了 deleted_at 列,但它没有更新该 id 上的任何内容
我也试过了
//second alternate method
$restoreAccount= SocialAccounts::withTrashed()->find($id)->update(['deleted_at' => NULL]);
//Third alternate method
$restoreAccount = SocialAccounts::withTrashed()->find($id);
$restoreAccount->deleted_at = NULL;
$restoreAccount->save();
我不确定我做错了什么,我们需要做些什么来实现恢复吗?我检查了官方 laravel 文档并遵循相同的。
【问题讨论】:
-
您确定请求中的其他内容没有删除它吗?即它正在恢复但又被删除?
-
我设法解决了。我正在使用数据库事务并且没有提交它我正在检查结果。傻我。感谢您的所有帮助。
标签: laravel eloquent soft-delete