81 lines
2.2 KiB
PHP
81 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Database\Factories\UserFactory;
|
|
use Illuminate\Database\Eloquent\Attributes\Fillable;
|
|
use Illuminate\Database\Eloquent\Attributes\Hidden;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Laravel\Passport\HasApiTokens;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
use Spatie\Activitylog\LogOptions;
|
|
|
|
#[Fillable(['first_name', 'last_name', 'email', 'phone', 'bio', 'password', 'status', 'avatar_url', 'meta', 'two_factor_secret', 'two_factor_recovery_codes', 'two_factor_confirmed_at'])]
|
|
#[Hidden(['password', 'remember_token', 'two_factor_secret', 'two_factor_recovery_codes'])]
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<UserFactory> */
|
|
use HasFactory, Notifiable, HasRoles, SoftDeletes, LogsActivity, HasApiTokens;
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
{
|
|
return LogOptions::defaults()
|
|
->logFillable()
|
|
->logOnlyDirty()
|
|
->dontSubmitEmptyLogs();
|
|
}
|
|
|
|
/**
|
|
* PHP 8.4 Property Hooks (Polyfill for PHP 8.3 environment)
|
|
*/
|
|
public function getFullName(): string
|
|
{
|
|
return "{$this->first_name} {$this->last_name}";
|
|
}
|
|
|
|
public function isActive(): bool
|
|
{
|
|
return $this->status === 'active' && !$this->deleted_at;
|
|
}
|
|
|
|
/**
|
|
* PHP 8.4 Asymmetric Visibility (Polyfill)
|
|
*/
|
|
protected ?string $avatarUrl = null;
|
|
|
|
public function getAvatarUrl(): ?string
|
|
{
|
|
return $this->avatarUrl;
|
|
}
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
'meta' => 'array',
|
|
'status' => 'string',
|
|
];
|
|
}
|
|
|
|
/**
|
|
* Sync avatarUrl with avatar_url attribute.
|
|
*/
|
|
public function setAvatar(string $path): void
|
|
{
|
|
$this->avatar_url = $path;
|
|
$this->avatarUrl = \Illuminate\Support\Facades\Storage::url($path);
|
|
}
|
|
}
|