123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- <?php
- namespace App\Http\Requests\API\Task;
- use App\Http\Requests\RuleHelper;
- use App\Models\Enums\TaskACL;
- use App\Models\User;
- 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;
- /**
- * 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
- {
- return [
- '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(),
- ];
- }
- }
|