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; } } 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')], 'title' => ['required', 'string', 'min:5', 'max:255'], 'text' => ['required', 'string', 'min:50'], 'keywords' => ['nullable', 'string', 'max:255'], 'backlinkUrl' => ['nullable', 'url', 'max:255'], ]); $user = auth()->user(); $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; $status = $submitStatus === 'review' ? PressReleaseStatus::Review : PressReleaseStatus::Draft; $slug = (new PressRelease)->generateUniqueSlug($this->title, [ 'portal' => $this->portal, 'language' => $this->language, ]); $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, 'slug' => $slug, 'text' => $this->text, 'keywords' => $this->keywords ?: null, 'backlink_url' => $this->backlinkUrl ?: null, 'status' => $status->value, ]); 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); $categories = Category::query() ->with('translations') ->where('is_active', true) ->orderBy('id') ->get(); return [ 'myCompanies' => $myCompanies, 'categories' => $categories, 'selectedPortalLabel' => $this->selectedCompany()?->portal?->label() ?? __('Wird aus der Firma übernommen'), ]; } public function updatedCompanyId(): void { $company = $this->selectedCompany(); if ($company?->portal) { $this->portal = $company->portal->value; } } private function selectedCompany(): ?Company { return app(CustomerCompanyContext::class) ->findFor(auth()->user(), (int) $this->companyId); } }; ?>
{{ __('Entwurf erstellen oder direkt zur Prüfung einreichen.') }}