|string> */ public function rules(): array { $requirementGroupIds = RequirementGroup::where('company_id',Auth::user()->company_id)->pluck('id')->toArray(); $IdsAndDitto=$requirementGroupIds; $IdsAndDitto[] = 'ditto'; $planIds = Plan::where('company_id',Auth::user()->company_id)->pluck('id')->toArray(); $planIdsAndDitto=$planIds; $planIdsAndDitto[] = 'ditto'; return [ '*.title' => 'required|max:255', '*.asset_id' => [ 'nullable', 'sometimes', Rule::exists('assets', 'id')->where($this->userCompanyWhere()), ], '*.priority' => 'required|in:1,2,3,4,ditto', '0.priority' => 'required|in:1,2,3,4', //第一个元素不能为ditto '*.requirement_group_id' => [ 'nullable', 'sometimes', Rule::in($IdsAndDitto), ], '0.requirement_group_id' => [ // 第一个元素不能为ditto 'nullable', 'sometimes', Rule::in($requirementGroupIds), ], '*.plan_id' => [ 'nullable', 'sometimes', Rule::in($planIdsAndDitto), ], '0.plan_id' => [ // 第一个元素不能为ditto 'nullable', 'sometimes', Rule::in($planIdsAndDitto), ], '*.project_id' => [ 'nullable', 'array', function ($attribute, $value, $fail) { $count = Project::where("company_id", Auth::user()->company_id)->whereIn('id', $value)->count(); if ($count != count($value)) { $fail('The selected project is invalid.'); } } ], '0.project_id' => [// 第一个元素不能为ditto 'nullable', 'array', function ($attribute, $value, $fail) { $count = Project::where("company_id", Auth::user()->company_id)->whereIn('id', $value)->count(); if ($count != count($value)) { $fail('The selected project is invalid.'); } } ], ]; } }