user(); $context = app(CustomerCompanyContext::class); $firstCompany = $context->selectedCompany($user) ?? $context->companiesFor($user)->first(); if ($firstCompany) { $this->companyId = $firstCompany->id; $this->portal = $firstCompany->portal?->value ?? Portal::Presseecho->value; $this->contactId = $this->defaultContactIdFor((int) $firstCompany->id); } } public function updatedCompanyId(): void { $company = $this->selectedCompany(); if ($company?->portal) { $this->portal = $company->portal->value; } $this->contactId = $company ? $this->defaultContactIdFor((int) $company->id) : null; unset($this->tags, $this->presubmitChecks); } public function addTag(string $tag): void { $tag = trim($tag); if ($tag === '') { return; } $existing = $this->tagsArray(); if (count($existing) >= 5) { return; } if (in_array($tag, $existing, true)) { return; } $existing[] = $tag; $this->keywords = implode(', ', $existing); unset($this->tags, $this->presubmitChecks); } public function removeTag(string $tag): void { $existing = array_values(array_filter( $this->tagsArray(), fn (string $existingTag): bool => $existingTag !== $tag, )); $this->keywords = implode(', ', $existing); unset($this->tags, $this->presubmitChecks); } public function save(string $submitStatus = 'draft'): void { $this->validate([ 'language' => ['required', Rule::in(['de', 'en'])], 'companyId' => ['required', 'integer'], 'categoryId' => ['required', 'integer', Rule::exists('categories', 'id')], 'contactId' => ['required', 'integer'], 'title' => ['required', 'string', 'min:5', 'max:255'], 'subtitle' => ['nullable', 'string', 'max:255'], 'text' => ['required', 'string', 'min:50'], 'keywords' => ['nullable', 'string', 'max:255'], 'backlinkUrl' => ['nullable', 'url', 'max:255'], 'boilerplateOverride' => ['nullable', 'string', 'max:5000'], ]); $user = auth()->user(); $company = $this->selectedCompany(); if (! $company) { $this->addError('companyId', __('Die gewählte Firma ist nicht Ihrem Account zugeordnet.')); return; } $contact = $this->companyContact((int) $this->contactId, (int) $company->id); if (! $contact) { $this->addError('contactId', __('Der gewählte Pressekontakt gehört nicht zu dieser Firma.')); return; } $this->portal = $company->portal?->value ?? Portal::Presseecho->value; $status = $submitStatus === 'review' ? PressReleaseStatus::Review : PressReleaseStatus::Draft; $slug = (new PressRelease)->generateUniqueSlug($this->title, [ 'portal' => $this->portal, 'language' => $this->language, ]); $cleanText = app(PressReleaseHtmlSanitizer::class)->clean($this->text); $pr = PressRelease::query()->create([ 'uuid' => (string) Str::uuid(), 'portal' => $this->portal, 'language' => $this->language, 'user_id' => $user->id, 'company_id' => (int) $this->companyId, 'category_id' => (int) $this->categoryId, 'title' => $this->title, 'subtitle' => trim($this->subtitle) ?: null, 'slug' => $slug, 'text' => $cleanText, 'boilerplate_override' => $this->useBoilerplateOverride && trim($this->boilerplateOverride) !== '' ? trim($this->boilerplateOverride) : null, 'keywords' => $this->keywords ?: null, 'backlink_url' => $this->backlinkUrl ?: null, 'status' => $status->value, ]); $pr->contacts()->sync([$contact->id]); session()->flash('success', $status === PressReleaseStatus::Review ? __('Pressemitteilung zur Prüfung eingereicht.') : __('Entwurf gespeichert.')); $this->redirect(route('me.press-releases.show', $pr->id), navigate: true); } public function with(): array { $user = auth()->user(); $context = app(CustomerCompanyContext::class); $myCompanies = $context->companiesFor($user); $selectedCompany = $this->selectedCompany(); $categories = Category::query() ->with('translations') ->where('is_active', true) ->orderBy('id') ->get(); return [ 'myCompanies' => $myCompanies, 'categories' => $categories, 'selectedCompany' => $selectedCompany, 'selectedCompanyContacts' => $selectedCompany ? $this->companyContacts((int) $selectedCompany->id) : Contact::query()->whereRaw('0 = 1')->get(), 'selectedPortalLabel' => $selectedCompany?->portal?->label() ?? __('Wird aus der Firma übernommen'), 'tagSuggestions' => $this->tagSuggestionsFor($selectedCompany), ]; } #[Computed] public function tags(): array { return $this->tagsArray(); } #[Computed] public function presubmitChecks(): array { $titleLen = mb_strlen(trim($this->title)); $textLen = app(PressReleaseHtmlSanitizer::class)->plainTextLength($this->text); $tagsCount = count($this->tagsArray()); return [ [ 'key' => 'title', 'status' => $titleLen >= 5 ? 'ok' : 'err', 'label' => __('Titel vorhanden'), 'sub' => $titleLen > 0 ? trans_choice('{0}Noch leer|{1}:n Zeichen|[2,*]:n Zeichen', $titleLen, ['n' => $titleLen]) : __('Noch leer'), ], [ 'key' => 'text', 'status' => $textLen >= 600 ? 'ok' : ($textLen >= 50 ? 'warn' : 'err'), 'label' => __('Mindestlänge Fließtext erreicht'), 'sub' => __(':n / 600 Zeichen empfohlen', ['n' => number_format($textLen, 0, ',', '.')]), ], [ 'key' => 'company', 'status' => $this->companyId ? 'ok' : 'err', 'label' => __('Firma zugeordnet'), 'sub' => $this->selectedCompany()?->name ?? __('Keine Firma gewählt'), ], [ 'key' => 'category', 'status' => $this->categoryId ? 'ok' : 'err', 'label' => __('Kategorie gewählt'), 'sub' => $this->categoryId ? '' : __('Kategorie ist Pflicht'), ], [ 'key' => 'contact', 'status' => $this->contactId ? 'ok' : 'err', 'label' => __('Pressekontakt zugeordnet'), 'sub' => $this->contactId ? '' : __('Mindestens ein Kontakt erforderlich'), ], [ 'key' => 'tags', 'status' => $tagsCount >= 1 ? 'ok' : 'warn', 'label' => __('Themen-Tags vergeben'), 'sub' => $tagsCount >= 1 ? trans_choice('{1}:n Tag|[2,*]:n Tags', $tagsCount, ['n' => $tagsCount]) : __('empfohlen für SEO & Auffindbarkeit'), ], ]; } /** * @return list */ private function tagsArray(): array { if (trim($this->keywords) === '') { return []; } return collect(explode(',', $this->keywords)) ->map(fn (string $tag): string => trim($tag)) ->filter() ->unique() ->values() ->all(); } private function defaultContactIdFor(int $companyId): ?int { return $this->companyContacts($companyId)->first()?->id; } /** * @return Collection */ private function companyContacts(int $companyId): Collection { return Contact::withoutGlobalScopes() ->where('company_id', $companyId) ->orderBy('last_name') ->orderBy('first_name') ->get(['id', 'company_id', 'first_name', 'last_name', 'responsibility', 'phone', 'email']); } private function companyContact(int $contactId, int $companyId): ?Contact { return Contact::withoutGlobalScopes() ->where('company_id', $companyId) ->whereKey($contactId) ->first(); } private function selectedCompany(): ?Company { if (! $this->companyId) { return null; } return app(CustomerCompanyContext::class) ->findFor(auth()->user(), (int) $this->companyId); } /** * @return list */ private function tagSuggestionsFor(?Company $company): array { $defaults = [ __('Mittelstand'), __('Unternehmen'), __('Eröffnung'), __('Innovation'), __('Nachhaltigkeit'), ]; if (! $company) { return $defaults; } $portalLabel = $company->portal?->label(); return array_values(array_unique(array_filter([ $portalLabel, $company->country_code === 'DE' ? __('Deutschland') : null, ...$defaults, ]))); } }; ?>
{{-- ============== PAGE HEADER ============== --}}
{{ __('User Backend') }} {{ __('Mein Bereich · Neue PM') }} {{ __('Entwurf') }}

{{ __('Neue Pressemitteilung') }}

{{ __('Schreibfläche links, Steuerung rechts. Pflichtfelder werden rechts in der Checkliste angezeigt.') }}

{{ __('Zur Liste') }}
{{-- ============== 2-COLUMN GRID ============== --}}
{{-- =================== LINKS: SCHREIBFLÄCHE =================== --}}
{{-- 1) FIRMA-SELEKTOR --}}
{{ __('Für Firma') }} @foreach ($myCompanies as $c) @endforeach {{ __('Boilerplate und Pressekontakt werden vorbefüllt.') }} @if ($selectedCompany) {{ __('Firmenprofil') }} @endif
{{-- 2) TITEL --}}
{{ __('Titel / Headline') }} *
@php $titleLen = mb_strlen($title); $titleClass = $titleLen >= 40 && $titleLen <= 90 ? 'good' : ($titleLen > 0 ? 'warn' : ''); $titleBar = min(100, max(0, ($titleLen / 100) * 100)); @endphp {{ $titleLen }} / 100 {{ __('KI-Titel · bald') }}

{{ __('40–90 Zeichen empfohlen. Konkret, ohne Marketing-Floskeln.') }}

{{-- 3) SUBTITLE --}}
{{ __('Untertitel') }} — {{ __('optional') }} @php $subLen = mb_strlen($subtitle); $subBar = min(100, max(0, ($subLen / 200) * 100)); @endphp {{ $subLen }} / 200
{{-- 4) FLIESSTEXT --}}
{{ __('Fließtext') }} *
@php $textLen = app(\App\Services\PressRelease\PressReleaseHtmlSanitizer::class)->plainTextLength($text); $textClass = $textLen >= 600 ? 'good' : ($textLen >= 50 ? 'warn' : ''); $textBar = min(100, max(0, ($textLen / 3500) * 100)); @endphp {{ number_format($textLen, 0, ',', '.') }} / 3.500 Z. {{ __('KI-Lektorat · bald') }}
{{ __('KI-Lektorat') }} {{ __('liest Korrektur, schlägt Kürzungen vor und prüft auf werbliche Sprache. Erscheint hier inline — bald verfügbar.') }}
{{-- 5) MEDIEN (nach Speichern verfügbar) --}}
{{ __('Medien / Bilder') }} — {{ __('nach Speichern verfügbar') }} {{ __('KI-Bildgenerierung · bald') }}

{{ __('Sobald die Pressemitteilung als Entwurf gespeichert ist, kannst du Bilder hinzufügen, ein Titelbild festlegen und Bildunterschriften/Alt-Texte pflegen.') }}

{{-- 6) ANHÄNGE (nach Speichern verfügbar) --}}
{{ __('Anhänge / Downloads') }} — {{ __('optional, nach Speichern verfügbar') }}
{{ __('PDF, Pressemappen und andere Dokumente kannst du nach dem ersten Speichern hinzufügen.') }}
{{-- 7) BOILERPLATE --}}
{{ __('Über das Unternehmen') }} — {{ __('Boilerplate aus Firma') }}
@if ($selectedCompany?->boilerplate)

{!! nl2br(e($selectedCompany->boilerplate)) !!}

@if ($selectedCompany->website)

{{ __('Web') }}: {{ $selectedCompany->website }}

@endif
@else
{{ __('Für diese Firma ist noch kein Boilerplate-Text hinterlegt. Du kannst entweder einen Override-Text für diese PM setzen oder das Firmenprofil ergänzen.') }}
@endif @if ($useBoilerplateOverride)
@endif

{{ __('Wird automatisch unter jeder Pressemitteilung dieser Firma angefügt. Pro PM editierbar.') }}

{{-- /Schreibfläche --}} {{-- =================== RECHTS: SETTINGS-SIDEBAR =================== --}}