12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- <?php
- namespace App\Http\Requests\API\Task;
- use App\Http\Requests\CustomFieldRuleHelper;
- use App\Http\Requests\NamingRuleHelper;
- use App\Http\Requests\RuleHelper;
- use App\Models\Enums\TaskACL;
- use Illuminate\Foundation\Http\FormRequest;
- use Illuminate\Support\Facades\Auth;
- use Illuminate\Validation\Rule;
- use Illuminate\Validation\Rules\Enum;
- class CreateOrUpdateRequest extends FormRequest
- {
- use RuleHelper, CustomFieldRuleHelper, NamingRuleHelper;
- /**
- * Determine if the user is authorized to make this request.
- */
- public function authorize(): bool
- {
- return true;
- }
- /**
- * Get the validation rules that apply to the request.
- *
- * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
- */
- public function rules(): array
- {
- $rules = [
- 'project_id' => [
- 'required',
- Rule::exists('projects', 'id')->where($this->userCompanyWhere()),
- ],
- 'requirement_id' => [
- 'required',
- 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' => [
- 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' => $this->usersCompanyRules(),
- 'mailto' => $this->usersCompanyRules(),
- ];
- $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];
- }
- }
|