id = $id; $pr = $this->getMyPR(); $this->authorize('update', $pr); abort_unless( in_array($pr->status->value, ['draft', 'rejected']), 403, __('Nur Entwürfe und abgelehnte Pressemitteilungen können bearbeitet werden.') ); $this->portal = $pr->portal->value; $this->language = $pr->language; $this->companyId = $pr->company_id; $this->categoryId = $pr->category_id; $this->title = $pr->title; $this->text = $pr->text; $this->keywords = $pr->keywords ?? ''; $this->backlinkUrl = $pr->backlink_url ?? ''; } public function updatedCompanyId(): void { $company = $this->selectedCompany(); if ($company?->portal) { $this->portal = $company->portal->value; } } public function save(): void { $this->validate([ 'language' => ['required', Rule::in(['de', 'en'])], 'companyId' => ['required', 'integer'], 'categoryId' => ['required', 'integer', Rule::exists('categories', 'id')], 'title' => ['required', 'string', 'min:5', 'max:255'], 'text' => ['required', 'string', 'min:50'], 'keywords' => ['nullable', 'string', 'max:255'], 'backlinkUrl' => ['nullable', 'url', 'max:255'], ]); $pr = $this->getMyPR(); $this->authorize('update', $pr); $company = $this->selectedCompany(); if (! $company) { $this->addError('companyId', __('Die gewählte Firma ist nicht Ihrem Account zugeordnet.')); return; } $this->portal = $company->portal?->value ?? Portal::Presseecho->value; $cleanText = app(PressReleaseHtmlSanitizer::class)->clean($this->text); $pr->update([ 'portal' => $this->portal, 'language' => $this->language, 'company_id' => (int) $this->companyId, 'category_id' => (int) $this->categoryId, 'title' => $this->title, 'text' => $cleanText, 'keywords' => $this->keywords ?: null, 'backlink_url' => $this->backlinkUrl ?: null, ]); session()->flash('success', __('Pressemitteilung gespeichert.')); $this->redirect(route('me.press-releases.show', $pr->id), navigate: true); } public function with(): array { $user = auth()->user(); $myCompanies = $user->companies()->orderBy('name')->get(['companies.id', 'companies.name', 'companies.portal']); $selectedCompany = $this->selectedCompany(); $categories = Category::query() ->with('translations') ->where('is_active', true) ->orderBy('id') ->get(); return [ 'myCompanies' => $myCompanies, 'categories' => $categories, 'selectedPortalLabel' => $selectedCompany?->portal?->label() ?? __('Wird aus der Firma übernommen'), ]; } private function getMyPR(): PressRelease { return PressRelease::withoutGlobalScopes() ->where('user_id', auth()->id()) ->findOrFail($this->id); } private function selectedCompany(): ?Company { return auth()->user() ->companies() ->whereKey((int) $this->companyId) ->first(['companies.id', 'companies.portal']); } }; ?>
{{-- ============== PAGE HEADER ============== --}}
{{ __('User Backend') }} {{ __('Mein Bereich · Bearbeiten') }} ID {{ $id }}

{{ __('Pressemitteilung bearbeiten') }}

{{ __('Inhalt und Metadaten der Pressemitteilung aktualisieren.') }}

{{ __('Zurück') }}
{{ __('Inhalt') }}
{{ __('Titel') }} * {{ __('Text') }} * {{ __('Stichwörter') }} {{ __('Backlink-URL') }}