Uh oh!
There was an error while loading. Please reload this page.
Restore "deleted" user #476
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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); |
Replies: 4 comments 29 replies
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
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); |
Well, there is almost always multiple ways to accomplish something, right? Solved. Working fine now. |
You probably need to call |
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
In case someone finds this later, here is the final solution: In the controller: publicfunctionmake_active($id)
{
$user = $this->userModel->withDeleted()->findById($id);
$user->fill(['deleted_at' => null]);
$this->userModel->save($user);
returnredirect() ->to("/admin/users/main")
->with('info', 'User successfully activated.');
}The custom model: namespaceApp\Models;
useCodeIgniter\Shield\Models\UserModel;
class Userp42Model extends UserModel
{
protectedfunctioninitialize()
{
$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);
} |
In case someone finds this later, here is the final solution:
In the controller:
The custom model: