Restore "deleted" user #476
-
I am trying to restore or undelete a user that was deleted using the softdelete function. The "deleted_at" column has a date in it (as it should). I should be able to restore the user by replacing the date with NULL, but I can't get it to save. I have added additional columns to update as a test during the update, and they update properly so I know I am updating the record, I just can't seem to remove the date in the "deleted_at" column. Any suggestions? $user = $this->userModel->withDeleted()->findById($id);
$user->fill(['deleted_at' => null]);
$this->userModel->save($user); |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 29 replies
-
I don't see any problem, column protected $allowedFields = [
...
'deleted_at',
]; code: $users = model('UserModel');
$user = $users->withDeleted()->findById(11);
$user->fill([
'deleted_at' => null
]);
return $users->save($user); |
Beta Was this translation helpful? Give feedback.
-
Well, there is almost always multiple ways to accomplish something, right?
Solved. Working fine now. |
Beta Was this translation helpful? Give feedback.
-
You probably need to call |
Beta Was this translation helpful? Give feedback.
-
In case someone finds this later, here is the final solution: In the controller: public function make_active($id)
{
$user = $this->userModel->withDeleted()->findById($id);
$user->fill(['deleted_at' => null]);
$this->userModel->save($user);
return redirect() ->to("/admin/users/main")
->with('info', 'User successfully activated.');
} The custom model: namespace App\Models;
use CodeIgniter\Shield\Models\UserModel;
class Userp42Model extends UserModel
{
protected function initialize()
{
$newAllowedFields = [
'fname','lname','user_uid',
'phone_home','phone_cell','phone_ext','phone_desk',
'is_superadmin',
'profile_image',
'calview','homepage',
];
// Merge properties with parent
$this->allowedFields = array_merge($this->allowedFields, $newAllowedFields);
} |
Beta Was this translation helpful? Give feedback.
In case someone finds this later, here is the final solution:
In the controller:
The custom model: