*/ public array $selectedEvents = []; /** @var array */ public array $availableEvents = [ 'link.clicked' => 'Link clicked', 'link.created' => 'Link created', 'link.updated' => 'Link updated', 'link.deleted' => 'Link deleted', ]; /** @return array */ protected function rules(): array { return [ 'url' => 'required|url|max:2048', 'secret' => 'nullable|string|max:255', 'selectedEvents' => 'required|array|min:1', 'selectedEvents.*' => 'string|in:'.implode(',', array_keys($this->availableEvents)), ]; } public function mount(string $workspaceUlid = ''): void { if ($workspaceUlid) { $workspace = Workspace::where('ulid', $workspaceUlid)->firstOrFail(); abort_unless( $workspace->owner_id === auth()->id() || $workspace->members()->where('user_id', auth()->id())->exists(), 404 ); $this->workspaceUlid = $workspaceUlid; $this->workspaceId = $workspace->id; } } public function save(): void { $this->validate(); $wsId = $this->workspaceId ?: require_workspace()->id; Webhook::create([ 'workspace_id' => $wsId, 'url' => $this->url, 'secret' => $this->secret ?: Str::random(32), 'events' => $this->selectedEvents, 'is_active' => true, ]); $this->dispatch('webhookCreated'); $this->closeModal(); } public function render(): View { return view('livewire.modals.create-webhook'); } }