when($userId > 0, function($query) use ($userId) { return $query->where('user_id', $userId); }) ->first(); if (!$pet) { if ($userId > 0) { $this->addError('宠物不存在或不属于当前用户'); } else { $this->addError('宠物不存在'); } return false; } return true; } catch (\Exception $e) { $this->addError('验证过程发生错误: ' . $e->getMessage()); return false; } } }