*/ public function rules(): array { $creating = ! $this->route('webhook') instanceof Webhook; $sometimes = $creating ? 'required' : 'sometimes'; return [ 'name' => [$sometimes, 'string', 'max:120'], 'url' => [ $sometimes, 'string', 'url', 'max:2048', // Refused now rather than at the first delivery; checked // again at every delivery all the same. new PublicHttpsUrl, ], 'events' => [$sometimes, 'array', 'min:1'], 'events.*' => [ 'string', 'distinct', function (string $attribute, mixed $value, Closure $fail): void { if (! is_string($value) || ! Webhook::isSubscribable($value)) { $fail(__('rules.webhooks.event', ['event' => (string) (is_scalar($value) ? $value : '')])); } }, ], 'secret' => [$creating ? 'sometimes' : 'prohibited', 'nullable', 'string', 'min:16', 'max:255'], 'rotate_secret' => [$creating ? 'prohibited' : 'sometimes', 'boolean'], 'include_personal_data' => ['sometimes', 'boolean'], 'is_active' => ['sometimes', 'boolean'], ]; } }