CreateOrUpdateRequest.php 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. <?php
  2. namespace App\Http\Requests\API\CustomField;
  3. use App\Http\Requests\RuleHelper;
  4. use App\Models\Enums\CustomFieldGroupType;
  5. use App\Models\Enums\CustomFieldType;
  6. use Illuminate\Foundation\Http\FormRequest;
  7. use Illuminate\Validation\Rule;
  8. use Illuminate\Validation\Rules\Enum;
  9. class CreateOrUpdateRequest extends FormRequest
  10. {
  11. use RuleHelper;
  12. /**
  13. * Determine if the user is authorized to make this request.
  14. */
  15. public function authorize(): bool
  16. {
  17. return true;
  18. }
  19. /**
  20. * Get the validation rules that apply to the request.
  21. *
  22. * @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
  23. */
  24. public function rules(): array
  25. {
  26. return [
  27. 'group_type' => ['required', new Enum(CustomFieldGroupType::class)],
  28. 'key' => 'required',
  29. 'group' => 'required',
  30. 'type' => [
  31. 'required',
  32. new Enum(CustomFieldType::class),
  33. ],
  34. 'required' => 'in:0,1',
  35. 'label' => 'required|array',
  36. 'options' => 'array',
  37. ];
  38. }
  39. public function importRules(): array
  40. {
  41. return [
  42. 'key' => 'required',
  43. 'type' => [
  44. 'required',
  45. new Enum(CustomFieldType::class),
  46. ],
  47. 'custom_key'=> 'required_if:type,3',
  48. 'custom_value'=>'required',
  49. ];
  50. }
  51. }