- {{ __('E-Mail') }}
- {{ $company->email ?: __('Keine E-Mail hinterlegt') }}
- {{ __('Telefon') }}
- {{ $company->phone ?: __('Kein Telefon hinterlegt') }}
- {{ __('Website') }}
- {{ $company->website ?: __('Keine Website hinterlegt') }}
selectedExistingContactId) { $this->attachExistingContact(); } } public function mount(int $id): void { $this->id = $id; $companyExists = Company::query()->whereKey($id)->exists(); if (! $companyExists) { session()->flash('error', __('Die angeforderte Firma wurde nicht gefunden.')); $this->redirect(route('admin.companies.index'), navigate: true); return; } } public function setTab(string $tab): void { if (in_array($tab, ['overview', 'contacts'], true)) { $this->activeTab = $tab; } } public function updatedContactLookup(): void { $this->selectedExistingContactId = null; } public function attachExistingContact(): void { if (! $this->selectedExistingContactId) { return; } $company = Company::query()->find($this->id); if (! $company) { session()->flash('error', __('Die angeforderte Firma wurde nicht gefunden.')); return; } $contact = Contact::query()->find($this->selectedExistingContactId); if (! $contact) { session()->flash('error', __('Der ausgewählte Kontakt wurde nicht gefunden.')); return; } if ($contact->company_id === $company->id) { session()->flash('info', __('Der Kontakt ist bereits dieser Firma zugeordnet.')); return; } $contact->update(['company_id' => $company->id]); $this->contactLookup = ''; $this->selectedExistingContactId = null; session()->flash('success', __('Kontakt wurde der Firma zugeordnet.')); } public function with(): array { $company = Company::query() ->with([ 'pressReleases' => fn ($query) => $query->latest('id')->limit(10), 'users:id,name,email', ]) ->withCount(['pressReleases', 'contacts', 'users']) ->find($this->id); if (! $company) { return [ 'company' => Company::make([ 'id' => $this->id, 'name' => __('Unbekannte Firma'), 'is_active' => false, ]), 'filteredContacts' => collect(), 'filteredContactsTotal' => 0, 'contactLookupResults' => collect(), 'recentPressReleases' => collect(), ]; } $filteredContacts = collect(); $filteredContactsTotal = 0; if ($this->activeTab === 'contacts') { $contactsQuery = Contact::query() ->where('company_id', $company->id) ->when(filled($this->contactSearch), function ($query): void { $search = trim($this->contactSearch); if ($this->supportsFullTextSearch($search)) { $query->whereFullText(['first_name', 'last_name', 'email', 'responsibility'], $search); return; } $query->where(function ($query) use ($search): void { $query->where('first_name', 'like', '%'.$search.'%') ->orWhere('last_name', 'like', '%'.$search.'%') ->orWhere('email', 'like', '%'.$search.'%') ->orWhere('responsibility', 'like', '%'.$search.'%'); }); }); $filteredContactsTotal = (clone $contactsQuery)->count(); $filteredContacts = $contactsQuery ->orderBy('last_name') ->orderBy('first_name') ->limit(100) ->get(['id', 'company_id', 'portal', 'first_name', 'last_name', 'responsibility', 'email']); } $contactLookupResults = collect(); $lookupTerm = trim($this->contactLookup); if ($this->activeTab === 'contacts' && mb_strlen($lookupTerm) >= 1) { $contactLookupResults = Contact::withoutGlobalScopes() ->with('company:id,name') ->where('company_id', '!=', $company->id) ->where(function ($query) use ($lookupTerm): void { if ($this->supportsFullTextSearch($lookupTerm)) { $query->whereFullText(['first_name', 'last_name', 'email', 'responsibility'], $lookupTerm); return; } $query ->where('first_name', 'like', '%'.$lookupTerm.'%') ->orWhere('last_name', 'like', '%'.$lookupTerm.'%') ->orWhere('email', 'like', '%'.$lookupTerm.'%'); }) ->orderBy('last_name') ->orderBy('first_name') ->limit(50) ->get(['id', 'company_id', 'first_name', 'last_name', 'email']); } return [ 'company' => $company, 'filteredContacts' => $filteredContacts, 'filteredContactsTotal' => $filteredContactsTotal, 'contactLookupResults' => $contactLookupResults, 'recentPressReleases' => $company->pressReleases, ]; } private function supportsFullTextSearch(string $term): bool { return mb_strlen($term) >= 3 && in_array(DB::connection()->getDriverName(), ['mysql', 'pgsql'], true); } private function portalBadgeColor(?Portal $portal): string { return match ($portal) { Portal::Presseecho => 'blue', Portal::Businessportal24 => 'purple', Portal::Both => 'zinc', default => 'zinc', }; } }; ?>
{{ __('Es werden die ersten :count Kontakte angezeigt. Bitte Suche eingrenzen, um weitere Treffer zu finden.', ['count' => $filteredContacts->count()]) }}
@endif