CreateOrUpdateRequest.php 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. <?php
  2. namespace App\Http\Requests\API\Task;
  3. use App\Http\Requests\RuleHelper;
  4. use App\Models\Enums\TaskACL;
  5. use App\Models\User;
  6. use Illuminate\Foundation\Http\FormRequest;
  7. use Illuminate\Support\Facades\Auth;
  8. use Illuminate\Validation\Rule;
  9. use Illuminate\Validation\Rules\Enum;
  10. class CreateOrUpdateRequest extends FormRequest
  11. {
  12. use RuleHelper;
  13. /**
  14. * Determine if the user is authorized to make this request.
  15. */
  16. public function authorize(): bool
  17. {
  18. return true;
  19. }
  20. /**
  21. * Get the validation rules that apply to the request.
  22. *
  23. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  24. */
  25. public function rules(): array
  26. {
  27. return [
  28. 'project_id' => [
  29. 'required',
  30. Rule::exists('projects', 'id')->where($this->userCompanyWhere()),
  31. ],
  32. 'requirement_id' => [
  33. 'required',
  34. Rule::exists('requirements', 'id')->where($this->userCompanyWhere()),
  35. ],
  36. 'naming_rule_id' => [
  37. Rule::when($this->get('naming_rule_id') > 0, [
  38. Rule::exists('naming_rules', 'id')->whereIn('company_id', [
  39. 0, Auth::user()->company_id,
  40. ]),
  41. ])
  42. ],
  43. 'assign' => [
  44. Rule::exists('users', 'id')->where($this->userCompanyWhere()),
  45. ],
  46. 'name' => 'required|max:255',
  47. 'parent_id' => [
  48. Rule::when($this->get('parent_id') > 0, [
  49. Rule::exists('tasks', 'id')->where($this->userCompanyWhere())->where("parent_id", 0),
  50. ])
  51. ],
  52. 'begin' => 'date',
  53. 'end' => 'date',
  54. 'acl' => [
  55. new Enum(TaskACL::class),
  56. ],
  57. 'whitelist' => $this->usersCompanyRules(),
  58. 'mailto' => $this->usersCompanyRules(),
  59. ];
  60. }
  61. }