CreateOrUpdateRequest.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  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. 'naming_rule_id'=>[
  41. 'required',
  42. Rule::exists('naming_rules', 'id')->where($this->userCompanyWhere()),
  43. ],
  44. 'key' => 'required',
  45. 'type' => [
  46. 'required',
  47. new Enum(CustomFieldType::class),
  48. ],
  49. 'custom_key'=> 'required_if:type,3',
  50. 'custom_value'=>'required',
  51. ];
  52. }
  53. }