|string> */ public function rules(): array { return [ 'asset_id' => [ 'nullable', Rule::exists('assets', 'id')->where($this->userCompanyWhere()), ], 'name' => 'required|max:255', 'abbr_name' => 'required|max:30', 'parent_id' => [ $this->parentIdExistsRule(), ] ]; } protected function parentIdExistsRule() { // 如果 parent_id 不为 0,返回 exists 规则 if ($this->input('parent_id') != 0) { return Rule::exists('requirement_groups', 'id')->where($this->userCompanyWhere())->where('asset_id', $this->input('asset_id')); } // 如果 parent_id 为 0,返回空数组以跳过 exists 验证 return []; } }