ldc-boutique-cnc-sable/app/Models/Customer.php

93 lines
2.6 KiB
PHP
Raw Permalink Normal View History

2026-06-14 21:32:07 +02:00
<?php
declare(strict_types=1);
namespace App\Models;
use App\Casts\CrmHashcodeCast;
2026-06-14 21:32:07 +02:00
use App\Casts\EmailCast;
use App\Traits\Models\HasUuidV7AsPrimaryKey;
use Domain\Contracts\CustomerDetails;
use Domain\Models\ValueObjects\Entities\ShopperId;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Attributes\Fillable;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Ramsey\Uuid\Uuid;
/**
* @property string $id
* @property \Domain\Models\ValueObjects\Email $email
* @property \Shared\ValueObjects\CrmHashcode $hashcode
2026-06-14 21:32:07 +02:00
* @property string|null $remember_token
* @property \Carbon\CarbonInterface|null $created_at
* @property \Illuminate\Support\Carbon|null $updated_at
* @property \Illuminate\Support\Carbon|null $last_login_at
* @property-read \App\Models\Employee|null $employee
* @property-read \Illuminate\Notifications\DatabaseNotificationCollection<int, \Illuminate\Notifications\DatabaseNotification> $notifications
* @property-read \App\Models\PasswordReset|null $resetToken
*
* @mixin \Eloquent
*/
#[Fillable([
'email',
'username',
])]
class Customer extends Authenticatable implements CustomerDetails, MustVerifyEmail
{
use HasUuidV7AsPrimaryKey;
use Notifiable;
#[\Override]
protected function casts(): array
{
return [
'email' => EmailCast::class,
'hashcode' => CrmHashcodeCast::class,
2026-06-14 21:32:07 +02:00
'last_login_at' => 'datetime',
];
}
#[\Override]
public function getAuthPassword(): string
{
return $this->hashcode->value;
2026-06-14 21:32:07 +02:00
}
#[\Override]
public function getEmailForVerification()
{
return $this->email->value;
}
#[\Override]
public function getEmailForPasswordReset()
{
return $this->email->value;
}
/** NOTE: Overload \Illuminate\Notifications\Notifiable trait */
public function routeNotificationForMail(): string
{
return $this->email->value;
}
public function getId(): ShopperId
{
return new ShopperId(Uuid::fromString($this->id));
}
/** @return \Illuminate\Database\Eloquent\Relations\HasOne<\App\Models\Employee,$this> */
public function employee(): HasOne
{
return $this->hasOne(Employee::class, 'customer_id');
}
/** @return \Illuminate\Database\Eloquent\Relations\HasOne<\App\Models\PasswordReset,$this> */
public function resetToken(): HasOne
{
return $this->hasOne(PasswordReset::class, 'email', 'email');
}
}