- Themen-Tag-Verwaltung (addTag/removeTag/tagsArray) war in create- und edit-Editor byte-identisch dupliziert -> Trait App\Livewire\Concerns\InteractsWithPressReleaseTags. - Kontaktauswahl je Firma (withoutGlobalScopes + where + Sortierung) aus create/edit/dashboard in Contact::scopeForCompany() zentralisiert. - Rechnungsadress-Pflichtfelder als BillingAddress::REQUIRED_FIELDS; isComplete() und neues completenessPercent() teilen die Liste, Dashboard nutzt es statt eigener Feldliste. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
76 lines
1.9 KiB
PHP
76 lines
1.9 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Enums\Portal;
|
|
use App\Scopes\PortalScope;
|
|
use Database\Factories\ContactFactory;
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
|
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
|
|
class Contact extends Model
|
|
{
|
|
/** @use HasFactory<ContactFactory> */
|
|
use HasFactory, SoftDeletes;
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::addGlobalScope(new PortalScope);
|
|
}
|
|
|
|
/**
|
|
* Kontakte einer Firma, portal-unabhängig (ohne GlobalScope) und in der
|
|
* fürs Kunden-Panel üblichen Sortierung. Single Source of Truth für die
|
|
* Kontaktauswahl in Erstellen/Bearbeiten und für Kontakt-Zählungen.
|
|
*/
|
|
public function scopeForCompany(Builder $query, int $companyId): Builder
|
|
{
|
|
return $query->withoutGlobalScopes()
|
|
->where('company_id', $companyId)
|
|
->orderBy('last_name')
|
|
->orderBy('first_name');
|
|
}
|
|
|
|
protected $fillable = [
|
|
'company_id',
|
|
'portal',
|
|
'salutation_key',
|
|
'title',
|
|
'first_name',
|
|
'last_name',
|
|
'responsibility',
|
|
'phone',
|
|
'fax',
|
|
'email',
|
|
'legacy_portal',
|
|
'legacy_id',
|
|
];
|
|
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'portal' => Portal::class,
|
|
'deleted_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
public function company(): BelongsTo
|
|
{
|
|
return $this->belongsTo(Company::class);
|
|
}
|
|
|
|
public function pressReleases(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(PressRelease::class, 'press_release_contact');
|
|
}
|
|
|
|
public function users(): BelongsToMany
|
|
{
|
|
return $this->belongsToMany(User::class)
|
|
->withTimestamps();
|
|
}
|
|
}
|