|string> */ public function rules(): array { $rules = [ 'project_id' => [ 'required', Rule::exists('projects', 'id')->where($this->userCompanyWhere()), ], 'requirement_id' => [ 'nullable', Rule::exists('requirements', 'id')->where($this->userCompanyWhere()), ], 'naming_rule_id' => [ Rule::when($this->get('naming_rule_id') > 0, [ Rule::exists('naming_rules', 'id')->whereIn('company_id', [ 0, Auth::user()->company_id, ]), ]) ], 'assign' => [ 'nullable', Rule::exists('users', 'id')->where($this->userCompanyWhere()), ], 'name' => 'required|max:255', 'parent_id' => [ Rule::when($this->get('parent_id') > 0, [ Rule::exists('tasks', 'id')->where($this->userCompanyWhere())->where("parent_id", 0), ]) ], 'begin' => 'date', 'end' => 'date', 'acl' => [ new Enum(TaskACL::class), ], 'whitelist' => [ 'array', 'nullable', function ($attribute, $value, $fail) { $userCount = User::where("company_id", Auth::user()->company_id)->whereIn('id', $value)->count(); if ($userCount != count($value)) { $fail('The selected user is invalid.'); } } ], 'mailto' => [ 'array', 'nullable', function ($attribute, $value, $fail) { $userCount = User::where("company_id", Auth::user()->company_id)->whereIn('id', $value)->count(); if ($userCount != count($value)) { $fail('The selected user is invalid.'); } } ], ]; $taskRules = $this->customFieldRuleByGroup("task", ['doc_type', 'task_type', 'doc_stage', "state", "suitability"]); if ($this->has("naming_rule_id") && $this->get("naming_rule_id") > 0) { $this->namingRuleCheck($this->get("naming_rule_id")); $namingRules = $this->customFieldRuleByGroup($this->get("naming_rule_id")); $rules = [...$rules, ... $namingRules]; } return [...$rules, ...$taskRules]; } }