Files
BauIN/app/Models/User.php
T
ChristophandClaude Opus 5.5 6aac8b0a16 Datenmodell Kern: Projekt, PFA, Vertrag, LV, Nachtrag, Dokument
- Mandant, Auftragnehmer, Projekt mit Suchreihenfolge, Abschnitt (PFA), Vertrag,
  Leistungsverzeichnis, Nachtrag (MKA nur als Bezug), Nachtragsposition, Dokument
- Projektmitglieder mit Projektrolle, Freigaben für vertrauliche Dokumente
- Mandant, Land und Projekt werden vom übergeordneten Datensatz übernommen;
  Fehlzuordnungen über Mandanten oder Projekte hinweg werden abgewiesen
- Feste Morph-Map, Factories, Demodaten (Musterbahn, PFA 1–4, N14/N16/N21), Tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-05 08:34:24 +02:00

86 lines
2.6 KiB
PHP

<?php
namespace App\Models;
use Database\Factories\UserFactory;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Attributes\Hidden;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Illuminate\Support\Carbon;
use Illuminate\Support\Str;
use Laravel\Fortify\Contracts\PasskeyUser;
use Laravel\Fortify\PasskeyAuthenticatable;
use Laravel\Fortify\TwoFactorAuthenticatable;
use Spatie\Permission\Traits\HasRoles;
/**
* @property int $id
* @property int|null $mandant_id
* @property string $name
* @property string $email
* @property string|null $locale
* @property Carbon|null $email_verified_at
* @property string $password
* @property string|null $two_factor_secret
* @property string|null $two_factor_recovery_codes
* @property Carbon|null $two_factor_confirmed_at
* @property string|null $remember_token
* @property Carbon|null $created_at
* @property Carbon|null $updated_at
*/
#[Fillable(['name', 'email', 'password', 'locale'])]
#[Hidden(['password', 'two_factor_secret', 'two_factor_recovery_codes', 'remember_token'])]
class User extends Authenticatable implements MustVerifyEmail, PasskeyUser
{
/** @use HasFactory<UserFactory> */
use HasFactory, HasRoles, Notifiable, PasskeyAuthenticatable, TwoFactorAuthenticatable;
/**
* Get the attributes that should be cast.
*
* @return array<string, string>
*/
protected function casts(): array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
/** @return BelongsTo<Mandant, $this> */
public function mandant(): BelongsTo
{
return $this->belongsTo(Mandant::class);
}
/**
* Projekte, in denen der Benutzer Mitglied ist; die Projektrolle steht im Pivot (rolle).
*
* @return BelongsToMany<Projekt, $this>
*/
public function projekte(): BelongsToMany
{
return $this->belongsToMany(Projekt::class, 'projekt_mitglieder')
->withPivot('rolle')
->withTimestamps();
}
/**
* Get the user's initials
*/
public function initials(): string
{
$initials = Str::initials($this->name, true);
return Str::length($initials) > 1
? Str::substr($initials, 0, 1).Str::substr($initials, -1)
: $initials;
}
}