where('id', '=', $user_id)->first(); // 检查用户是否存在,避免传入null导致类型错误 if (!$user) { throw new \Exception("用户不存在: user_id={$user_id}"); } SessionApp::setLogin($user); } }