public function __construct() { $this->middleware('admin'); $root = User::withTrashed()->find(User::ROOT_USER); if (!$root) { $root = new User(); $root->name = 'Root'; $root->acronym = 'root'; $root->display_name = 'Root User'; $root->user_id = null; $root->save(); $root->id = User::ROOT_USER; $root->save(); } else { if ($root->trashed()) { $root->restore(); } if ($root->user_id != null) { $root->user_id = null; $root->save(); } } $more = User::withTrashed()->whereUserId(null)->where('id', '<>', User::ROOT_USER); if ($more->count() > 0) { $more->update(['user_id' => User::ROOT_USER]); } }