[英]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.