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 updatedTargetUrl(string $value): void { if ($this->autoSlug && $value) { $this->slug = Str::random(6); } } public function updatedSlug(): void { $this->autoSlug = false; } public function regenerateSlug(): void { $this->slug = Str::random(6); $this->autoSlug = true; } public function generateSlug(): void { if (empty($this->slug)) { $this->slug = Str::random(6); } } public function suggestSlugs(): void { if (! $this->targetUrl) { return; } $this->aiLoading = true; $this->slugSuggestions = app(SlugSuggester::class)->suggest($this->targetUrl); $this->aiLoading = false; } public function pickSuggestion(string $slug): void { $this->slug = $slug; $this->autoSlug = false; $this->slugSuggestions = []; } public function save(): void { $this->validate(); $wsId = $this->workspaceId; if (! $wsId) { $ws = current_workspace(); if (! $ws) { $this->addError('targetUrl', 'Workspace nicht gefunden.'); return; } $wsId = $ws->id; } $slug = $this->slug ?: Str::random(6); $link = Link::create([ 'workspace_id' => $wsId, 'target_url' => $this->targetUrl, 'slug' => $slug, 'title' => $this->title ?: null, 'status' => 'active', 'created_by' => auth()->id(), ]); $this->dispatch('link-created', linkId: $link->ulid)->to(Index::class); $this->dispatch('toast', message: 'Link erstellt', type: 'success'); $this->closeModal(); } public function render(): View { return view('livewire.modals.create-link'); } }