presseportale/app/Livewire/Concerns/ProvidesUserFormRules.php
Kevin Adametz 26ce2544f0 UI: Agentur-Angaben im Profil, Firmen-Typ-Auswahl entfernt
A5 des Umbaus Agentur-Attribution → User-Profil: Kunden-Profil erhält
den Abschnitt „Agentur-Angaben" (Feld Agentur-/Verteilername, öffentlich
als Übermittler sichtbar). Firma-Anlegen (Kunde + Admin) und
Admin-Firma-Bearbeiten kommen ohne Typ-Feld aus — Neuanlagen sind immer
type=company. Firmen-Übersicht zeigt kein Typ-Label mehr. Admin-User-
Formulare pflegen agency_name; die Detailseite zeigt den Übermittler
als Badge. CompanyFactory erzeugt keine zufälligen Agentur-Typen mehr.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-07-08 09:44:17 +00:00

75 lines
2.7 KiB
PHP

<?php
namespace App\Livewire\Concerns;
use App\Enums\Portal;
use App\Enums\RegistrationType;
use Illuminate\Validation\Rule;
/**
* Gemeinsame Validierungsregeln der Benutzer-Formulare (Anlegen/Bearbeiten).
* Nur die zwischen beiden Formularen identischen Blöcke leben hier; die rein
* im Bearbeiten genutzten Profil-/Kontakt-Regeln bleiben dort inline.
*/
trait ProvidesUserFormRules
{
/**
* Identitäts-Stammdaten. Beim Bearbeiten ignoriert die E-Mail-Unique-Regel
* den eigenen Datensatz.
*
* @return array<string, mixed>
*/
protected function userIdentityRules(?int $ignoreUserId = null): array
{
$emailUnique = Rule::unique('users', 'email');
if ($ignoreUserId !== null) {
$emailUnique = $emailUnique->ignore($ignoreUserId);
}
return [
'name' => ['required', 'string', 'max:255'],
'agencyName' => ['nullable', 'string', 'max:190'],
'email' => ['required', 'email', $emailUnique],
'portal' => ['required', Rule::in(array_map(static fn (Portal $portal): string => $portal->value, Portal::cases()))],
'registrationType' => ['required', Rule::in(array_map(static fn (RegistrationType $type): string => $type->value, RegistrationType::cases()))],
'language' => ['required', 'string', Rule::in(['de', 'en'])],
];
}
/**
* Rollen-Auswahl plus Firmen-Verknüpfungen mit Pivot-Rolle.
*
* @return array<string, mixed>
*/
protected function userRolesAndCompaniesRules(): array
{
return [
'selectedRoles' => ['required', 'array', 'min:1'],
'selectedRoles.*' => ['string', Rule::exists('roles', 'name')],
'linkedCompanyIds' => ['array'],
'linkedCompanyIds.*' => ['integer', Rule::exists('companies', 'id')],
'companyRoles' => ['array'],
'companyRoles.*' => ['string', Rule::in(['member', 'responsible', 'owner'])],
];
}
/**
* Rechnungsadresse (optional; nur gespeichert, wenn vollständig).
*
* @return array<string, mixed>
*/
protected function userBillingRules(): array
{
return [
'billing.salutation_key' => ['nullable', 'string', 'max:20'],
'billing.title' => ['nullable', 'string', 'max:80'],
'billing.name' => ['nullable', 'string', 'max:255'],
'billing.address1' => ['nullable', 'string', 'max:255'],
'billing.address2' => ['nullable', 'string', 'max:255'],
'billing.postal_code' => ['nullable', 'string', 'max:20'],
'billing.city' => ['nullable', 'string', 'max:120'],
'billing.country_code' => ['nullable', 'string', 'size:2'],
];
}
}