StoreRuleRequest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. <?php
  2. namespace App\Http\Requests;
  3. use Illuminate\Foundation\Http\FormRequest;
  4. use Illuminate\Validation\Rule;
  5. class StoreRuleRequest extends FormRequest
  6. {
  7. /**
  8. * Determine if the user is authorized to make this request.
  9. *
  10. * @return bool
  11. */
  12. public function authorize()
  13. {
  14. return true;
  15. }
  16. /**
  17. * Get the validation rules that apply to the request.
  18. *
  19. * @return array
  20. */
  21. public function rules()
  22. {
  23. return [
  24. 'name' => [
  25. 'required',
  26. 'string',
  27. 'max:50'
  28. ],
  29. 'conditions' => [
  30. 'required',
  31. 'array',
  32. 'max:5'
  33. ],
  34. 'conditions.*.type' => [
  35. 'required',
  36. Rule::in([
  37. 'subject',
  38. 'sender',
  39. 'alias'
  40. ])
  41. ],
  42. 'conditions.*.match' => [
  43. 'sometimes',
  44. 'required',
  45. Rule::in([
  46. 'is exactly',
  47. 'is not',
  48. 'contains',
  49. 'does not contain',
  50. 'starts with',
  51. 'does not start with',
  52. 'ends with',
  53. 'does not end with'
  54. ])
  55. ],
  56. 'conditions.*.values' => [
  57. 'required',
  58. 'array',
  59. 'min:1',
  60. 'max:10'
  61. ],
  62. 'conditions.*.values.*' => [
  63. 'distinct',
  64. ],
  65. 'actions' => [
  66. 'required',
  67. 'array',
  68. 'max:5'
  69. ],
  70. 'actions.*.type' => [
  71. 'required',
  72. Rule::in([
  73. 'subject',
  74. 'displayFrom',
  75. 'encryption',
  76. 'banner',
  77. 'block',
  78. 'webhook'
  79. ]),
  80. ],
  81. 'actions.*.value' => [
  82. 'required',
  83. 'max:50'
  84. ],
  85. 'operator' => [
  86. 'required',
  87. 'in:AND,OR'
  88. ]
  89. ];
  90. }
  91. }