繁体   English   中英

无法在Laravel中恢复软删除的数据

[英]Not able to restore soft deleted data in laravel

我想知道为什么我无法在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官方文档,并遵循相同的步骤。

$ restoreAccount = SocialAccounts :: onlyTrashed()-> find($ id)-> restore();

我不知道您是否已经找到答案,但是也许您可以在控制器中尝试一下

public function restore($id) 
{
    $restoreAccount = SocialAccounts::onlyTrashed()->->where('id', $id)->restore();
    return redirect()->route('your.route');
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM