Skip to content

Restore "deleted" user #476

Answered by MarcPinnell
MarcPinnell asked this question in Q&A
Oct 14, 2022 · 4 comments · 29 replies
Discussion options

You must be logged in to vote

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',
		];
		//…

Replies: 4 comments 29 replies

Comment options

You must be logged in to vote
3 replies
@MarcPinnell
Comment options

@datamweb
Comment options

@MarcPinnell
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
26 replies
@datamweb
Comment options

@paulbalandan
Comment options

@kenjis
Comment options

@MGatner
Comment options

@MarcPinnell
Comment options

Comment options

You must be logged in to vote
0 replies
Answer selected by MarcPinnell
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
good first issue Good for newcomers
5 participants