I wonder why I am unable to restore soft deleted data in 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
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.
$ 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');
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.