CreateOrUpdateRequest.php 1.3 KB

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