diff --git a/app/Livewire/Pages/Bio/Edit.php b/app/Livewire/Pages/Bio/Edit.php index 037fb83..f086e85 100644 --- a/app/Livewire/Pages/Bio/Edit.php +++ b/app/Livewire/Pages/Bio/Edit.php @@ -43,10 +43,30 @@ class Edit extends Component { $page = BioPage::findOrFail($this->pageId); + $newSlug = $state['slug'] ?? $page->slug; + + $slugTaken = BioPage::where('workspace_id', $page->workspace_id) + ->where('slug', $newSlug) + ->where('id', '!=', $page->id) + ->whereNull('deleted_at') + ->exists(); + + if ($slugTaken) { + $this->dispatch('toast', message: 'Slug "' . $newSlug . '" ist bereits vergeben.', type: 'error'); + + return; + } + + if (! preg_match('/^[a-zA-Z0-9_-]{1,64}$/', $newSlug)) { + $this->dispatch('toast', message: 'Slug: nur Buchstaben, Zahlen, - und _. Max 64 Zeichen.', type: 'error'); + + return; + } + $displayName = $state['profile']['displayName'] ?? ''; $page->update([ - 'slug' => $state['slug'] ?? $page->slug, + 'slug' => $newSlug, 'title' => ['en' => $displayName, 'de' => $displayName], 'is_published' => false, 'theme' => [ diff --git a/database/migrations/2026_05_17_600000_bio_pages_unique_workspace_slug.php b/database/migrations/2026_05_17_600000_bio_pages_unique_workspace_slug.php new file mode 100644 index 0000000..68eb336 --- /dev/null +++ b/database/migrations/2026_05_17_600000_bio_pages_unique_workspace_slug.php @@ -0,0 +1,25 @@ +unique(['workspace_id', 'slug'], 'bio_pages_workspace_slug_unique'); + }); + } + + public function down(): void + { + Schema::table('bio_pages', function (Blueprint $table) { + $table->dropUnique('bio_pages_workspace_slug_unique'); + }); + } +};