简体   繁体   English

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

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

I wonder why I am unable to restore soft deleted data in laravel. 我想知道为什么我无法在laravel中恢复软删除的数据。 I have did everything right but not sure what I am missing so I cannot able to restore data. 我已正确执行所有操作,但不确定我丢失了什么,因此无法还原数据。

My model is 我的模特是

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'];
}

I have used soft delete traits. 我已经使用了软删除特征。 For restore my soft deleted data I am doing something like below 为了恢复我的软删除数据,我正在做下面的事情

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

but It doesn't restore data, I am assuming when we restore data laravel NULL the deleted_at column, but it is not updating anything on that id 但是它不还原数据,我假设当我们还原数据时,laravel NULL的deleted_at列为空,但是它并没有更新该ID

I have also tried 我也尝试过

//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();

I am not sure what wrong I am doing, may there is anything we have to do to achieve restore? 我不确定自己在做什么错,请问我们需要做些什么来实现还原? I checked official laravel doc and follow the same. 我检查了laravel官方文档,并遵循相同的步骤。

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

I dont know if you already find the answer or not, but maybe you can try this in your controller 我不知道您是否已经找到答案,但是也许您可以在控制器中尝试一下

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