- Added UnsubscribeFromNewsletter action and input/output classes. - Introduced CrmHashcode value object and its cast. - Updated NewsletterController to use the new unsubscribe action. - Enhanced validation in UnsubscribeNewsletterRequest.
92 lines
2.6 KiB
PHP
92 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Models;
|
|
|
|
use App\Casts\CrmHashcodeCast;
|
|
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
|
|
* @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,
|
|
'last_login_at' => 'datetime',
|
|
];
|
|
}
|
|
|
|
#[\Override]
|
|
public function getAuthPassword(): string
|
|
{
|
|
return $this->hashcode->value;
|
|
}
|
|
|
|
#[\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');
|
|
}
|
|
}
|