2025-12-30 15:03:19 +08:00
|
|
|
<?php
|
|
|
|
|
|
2026-01-26 10:37:47 +08:00
|
|
|
namespace App\Modules\Core\Models;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
|
|
|
use Illuminate\Notifications\Notifiable;
|
2026-01-13 13:30:51 +08:00
|
|
|
use Spatie\Permission\Traits\HasRoles;
|
2026-01-16 17:36:37 +08:00
|
|
|
use Spatie\Activitylog\Traits\LogsActivity;
|
|
|
|
|
use Spatie\Activitylog\LogOptions;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
2026-02-06 11:56:29 +08:00
|
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
|
|
2025-12-30 15:03:19 +08:00
|
|
|
class User extends Authenticatable
|
|
|
|
|
{
|
|
|
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
2026-02-06 11:56:29 +08:00
|
|
|
use HasFactory, Notifiable, HasRoles, LogsActivity, HasApiTokens;
|
2025-12-30 15:03:19 +08:00
|
|
|
|
|
|
|
|
/**
|
2026-01-26 14:59:24 +08:00
|
|
|
* 可批量賦值的屬性。
|
2025-12-30 15:03:19 +08:00
|
|
|
*
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
2026-01-26 14:59:24 +08:00
|
|
|
/**
|
|
|
|
|
* 建立模型的新工廠實例。
|
|
|
|
|
*
|
|
|
|
|
* @return \Illuminate\Database\Eloquent\Factories\Factory
|
|
|
|
|
*/
|
|
|
|
|
protected static function newFactory()
|
|
|
|
|
{
|
|
|
|
|
return \Database\Factories\UserFactory::new();
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-30 15:03:19 +08:00
|
|
|
protected $fillable = [
|
|
|
|
|
'name',
|
|
|
|
|
'email',
|
2026-01-07 14:44:01 +08:00
|
|
|
'username',
|
2025-12-30 15:03:19 +08:00
|
|
|
'password',
|
2026-02-03 11:51:46 +08:00
|
|
|
'is_active',
|
2025-12-30 15:03:19 +08:00
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-26 14:59:24 +08:00
|
|
|
* 序列化時應隱藏的屬性。
|
2025-12-30 15:03:19 +08:00
|
|
|
*
|
|
|
|
|
* @var list<string>
|
|
|
|
|
*/
|
|
|
|
|
protected $hidden = [
|
|
|
|
|
'password',
|
|
|
|
|
'remember_token',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-26 14:59:24 +08:00
|
|
|
* 取得應進行轉換的屬性。
|
2025-12-30 15:03:19 +08:00
|
|
|
*
|
|
|
|
|
* @return array<string, string>
|
|
|
|
|
*/
|
|
|
|
|
protected function casts(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'email_verified_at' => 'datetime',
|
2026-02-03 11:51:46 +08:00
|
|
|
|
2025-12-30 15:03:19 +08:00
|
|
|
'password' => 'hashed',
|
2026-02-03 11:51:46 +08:00
|
|
|
'is_active' => 'boolean',
|
2025-12-30 15:03:19 +08:00
|
|
|
];
|
|
|
|
|
}
|
2026-01-16 17:36:37 +08:00
|
|
|
|
|
|
|
|
public function getActivitylogOptions(): LogOptions
|
|
|
|
|
{
|
|
|
|
|
return LogOptions::defaults()
|
|
|
|
|
->logAll()
|
|
|
|
|
->logOnlyDirty()
|
|
|
|
|
->dontSubmitEmptyLogs();
|
|
|
|
|
}
|
2026-01-19 16:13:22 +08:00
|
|
|
|
|
|
|
|
public function tapActivity(\Spatie\Activitylog\Contracts\Activity $activity, string $eventName)
|
|
|
|
|
{
|
|
|
|
|
$activity->properties = $activity->properties->merge([
|
|
|
|
|
'snapshot' => [
|
|
|
|
|
'name' => $this->name,
|
|
|
|
|
'username' => $this->username,
|
|
|
|
|
]
|
|
|
|
|
]);
|
|
|
|
|
}
|
2025-12-30 15:03:19 +08:00
|
|
|
}
|