BatchCreateRequest.php 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. <?php
  2. namespace App\Http\Requests\API\Task;
  3. use App\Http\Requests\RuleHelper;
  4. use function DragonCode\Support\Http\exists;
  5. use Illuminate\Foundation\Http\FormRequest;
  6. use Illuminate\Validation\Rule;
  7. class BatchCreateRequest extends FormRequest
  8. {
  9. use RuleHelper;
  10. /**
  11. * Determine if the user is authorized to make this request.
  12. */
  13. public function authorize(): bool
  14. {
  15. return true;
  16. }
  17. /**
  18. * Get the validation rules that apply to the request.
  19. *
  20. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  21. */
  22. public function rules(): array
  23. {
  24. return [
  25. 'project_id' => [
  26. 'required',
  27. Rule::exists('projects', 'id')->where($this->userCompanyWhere()),
  28. ],
  29. 'parent_id' => [
  30. 'required',
  31. Rule::when(
  32. $this->get('parent_id') != 0,
  33. Rule::exists('tasks', 'id')->where(function ($query) {
  34. $this->userCompanyWhere($query);
  35. })
  36. ),
  37. ],
  38. 'items' => [
  39. 'required', 'array'
  40. ]
  41. ];
  42. }
  43. }