Files
crewli/api/app/Models/User.php
bert.hausmans eb1a0ac666 feat: complete person identity matching system with fuzzy detection, revert, and manual link
Implements the full identity matching engine: email matching (HIGH confidence),
fuzzy name matching with Levenshtein distance (MEDIUM confidence, upgradable to
HIGH with DOB tiebreaker), manual link/unlink, revert confirmed matches, and
automatic detection via PersonObserver. Includes 33 comprehensive tests, frontend
integration with confirm/dismiss/unlink UI, and match indicators in the persons list.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-14 08:44:24 +02:00

100 lines
2.4 KiB
PHP

<?php
declare(strict_types=1);
namespace App\Models;
use Illuminate\Database\Eloquent\Concerns\HasUlids;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Spatie\Permission\Traits\HasRoles;
final class User extends Authenticatable
{
use HasApiTokens;
use HasFactory;
use HasRoles;
use HasUlids;
use Notifiable;
use SoftDeletes;
protected $fillable = [
'first_name',
'last_name',
'date_of_birth',
'email',
'password',
'timezone',
'locale',
'avatar',
];
public function getFullNameAttribute(): string
{
return trim("{$this->first_name} {$this->last_name}");
}
public function getNameAttribute(): string
{
return $this->full_name;
}
protected $hidden = [
'password',
'remember_token',
];
protected function casts(): array
{
return [
'date_of_birth' => 'date',
'email_verified_at' => 'datetime',
'password' => 'hashed',
];
}
public function organisations(): BelongsToMany
{
return $this->belongsToMany(Organisation::class, 'organisation_user')
->withPivot('role')
->withTimestamps();
}
public function events(): BelongsToMany
{
return $this->belongsToMany(Event::class, 'event_user_roles')
->withPivot('role')
->withTimestamps();
}
public function invitations(): HasMany
{
return $this->hasMany(UserInvitation::class, 'invited_by_user_id');
}
public function identityMatches(): HasMany
{
return $this->hasMany(PersonIdentityMatch::class, 'matched_user_id');
}
public function persons(): HasMany
{
return $this->hasMany(Person::class, 'user_id');
}
public function organisationTags(): HasMany
{
return $this->hasMany(UserOrganisationTag::class);
}
public function tagsForOrganisation(string $organisationId): HasMany
{
return $this->organisationTags()->where('organisation_id', $organisationId);
}
}