resetErrorBag('companyId'); } public function updatedTitle(): void { $this->resetErrorBag('title'); } public function save(string $submitStatus = 'draft'): void { $this->validate([ 'portal' => ['required', Rule::in(array_map(fn (Portal $p) => $p->value, Portal::cases()))], 'language' => ['required', Rule::in(['de', 'en'])], 'companyId' => ['required', 'integer', Rule::exists('companies', 'id')], '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'], ]); $status = match ($submitStatus) { 'review' => PressReleaseStatus::Review, default => 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' => auth()->id(), 'company_id' => (int) $this->companyId, 'category_id' => (int) $this->categoryId, 'title' => $this->title, 'slug' => $slug, 'text' => $cleanText, 'keywords' => $this->keywords ?: null, 'backlink_url' => $this->backlinkUrl ?: null, 'status' => $status->value, 'no_export' => $this->noExport, ]); session()->flash('success', $status === PressReleaseStatus::Review ? __('Pressemitteilung zur Prüfung eingereicht.') : __('Pressemitteilung als Entwurf gespeichert.')); $this->redirect(route('admin.press-releases.edit', $pr->id), navigate: true); } public function with(): array { $term = trim($this->companySearch); $companies = Company::withoutGlobalScopes() ->when(filled($term), function ($q) use ($term): void { if ($this->supportsFullTextSearch($term)) { $q->whereFullText(['name', 'email', 'slug'], $term); return; } $q->where('name', 'like', '%'.$term.'%') ->orWhere('slug', 'like', '%'.$term.'%'); }) ->when(blank($term) && $this->companyId, fn ($q) => $q->whereIn('id', [(int) $this->companyId])) ->when(blank($term) && ! $this->companyId, fn ($q) => $q->whereRaw('0 = 1')) ->orderBy('name') ->limit(50) ->get(['id', 'name']); return [ 'companies' => $companies, 'categories' => $this->categoryOptions(), 'portalOptions' => array_filter(Portal::cases(), fn (Portal $p) => $p !== Portal::Both), ]; } private function categoryOptions(): Collection { return app(AdminPerformanceCache::class)->remember(AdminPerformanceCache::ActiveCategoryOptions, AdminPerformanceCache::OptionsTtl, fn () => Category::query() ->with('translations') ->where('is_active', true) ->orderBy('id') ->get()); } private function supportsFullTextSearch(string $term): bool { return mb_strlen($term) >= 3 && in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'], true); } }; ?>
{{ __('Entwurf erstellen oder direkt zur Prüfung einreichen.') }}