integer('company'); if ($prefilledCompanyId > 0) { $this->companyId = $prefilledCompanyId; $company = Company::withoutGlobalScopes()->find($prefilledCompanyId); $this->portal = $company?->portal?->value ?? Portal::Both->value; $this->isCompanyPrefilled = true; } else { $this->portal = Portal::Both->value; } } public function updatedCompanySearch(): void { $this->resetErrorBag('companyId'); } public function updatedCompanyId(): void { if (! $this->companyId) { return; } $company = Company::withoutGlobalScopes()->find((int) $this->companyId); if ($company) { $this->portal = $company->portal?->value ?? Portal::Both->value; } } public function save(): void { $validated = $this->validate([ 'companyId' => ['required', 'integer', Rule::exists('companies', 'id')], 'portal' => ['required', Rule::in(array_map(static fn (Portal $portal): string => $portal->value, Portal::cases()))], 'salutationKey' => ['nullable', 'string', 'max:20'], 'title' => ['nullable', 'string', 'max:80'], 'firstName' => ['nullable', 'string', 'max:80'], 'lastName' => ['nullable', 'string', 'max:80'], 'responsibility' => ['nullable', 'string', 'max:255'], 'phone' => ['nullable', 'string', 'max:40'], 'fax' => ['nullable', 'string', 'max:40'], 'email' => ['nullable', 'email', 'max:255'], ]); $this->companySearch = ''; $contact = Contact::query()->create([ 'company_id' => (int) $validated['companyId'], 'portal' => $validated['portal'], 'salutation_key' => $validated['salutationKey'] ?: null, 'title' => $validated['title'] ?: null, 'first_name' => $validated['firstName'] ?: null, 'last_name' => $validated['lastName'] ?: null, 'responsibility' => $validated['responsibility'] ?: null, 'phone' => $validated['phone'] ?: null, 'fax' => $validated['fax'] ?: null, 'email' => $validated['email'] ?: null, ]); session()->flash('success', __('Kontakt wurde angelegt.')); $this->redirect(route('admin.contacts.edit', $contact->id), navigate: true); } public function with(): array { $term = trim($this->companySearch); $companies = Company::withoutGlobalScopes() ->when(filled($term), function ($q) use ($term): void { $q->where(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, function ($q): void { // Aktuell gewählte Firma immer einschließen, damit das Combobox-Label korrekt angezeigt wird $q->whereIn('id', [(int) $this->companyId]); }) ->when(blank($term) && ! $this->companyId, function ($q): void { // Ohne Suchbegriff und ohne Auswahl: keine Ergebnisse $q->whereRaw('0 = 1'); }) ->orderBy('name') ->limit(50) ->get(['id', 'name']); return [ 'companies' => $companies, 'salutations' => config('salutations.items', []), 'portalOptions' => Portal::cases(), ]; } private function supportsFullTextSearch(string $term): bool { return mb_strlen($term) >= 3 && in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'], true); } }; ?>
{{-- ============== PAGE HEADER ============== --}}
{{ __('Admin Backend') }} {{ __('Administration · Pressekontakte') }} @if ($isCompanyPrefilled && $companyId) {{ __('Firma vorausgewählt') }} @endif

{{ __('Kontakt anlegen') }}

{{ __('Kontakt einer Firma zuordnen und Stammdaten erfassen.') }}

{{ __('Zurück') }}
{{ __('Zuordnung') }}
{{ __('Firma') }} @foreach ($companies as $company) {{ $company->name }} @endforeach @if (blank(trim($companySearch))) {{ __('Mindestens 1 Zeichen eingeben…') }} @else {{ __('Keine Firma gefunden.') }} @endif {{ __('Portal') }} @foreach ($portalOptions as $portalOption) @endforeach
{{ __('Kontaktdaten') }}
{{ __('Anrede') }} @foreach ($salutations as $key => $labels) @endforeach {{ __('Titel') }} {{ __('Vorname') }} {{ __('Nachname') }} {{ __('Verantwortlichkeit') }} {{ __('E-Mail') }} {{ __('Telefon') }} {{ __('Fax') }}
{{ __('Abbrechen') }} {{ __('Kontakt anlegen') }}