- 機台日誌:對齊 Luxury UI 規範,實作整合式佈局與分頁組件。 - 多語系:完成機台日誌繁、英、日三語系翻譯與動態處理。 - UI 規範:更新 SKILL.md 定義「標準列表 Bible」。 - 後端:完善 TenantScoped 隔離邏輯,修復儀表板死循環與 User Model 缺失。 - IoT:擴展機台、會員 Model 並建立交易、商品、狀態等核心表結構。 - 基礎設施:設置台北時區與 Docker 環境變數同步。
101 lines
2.2 KiB
PHP
101 lines
2.2 KiB
PHP
<?php
|
|
|
|
namespace App\Models\System;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
use Laravel\Sanctum\HasApiTokens;
|
|
|
|
use App\Traits\TenantScoped;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Spatie\Permission\Traits\HasRoles;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
use HasApiTokens, HasFactory, Notifiable, HasRoles, TenantScoped, SoftDeletes;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $fillable = [
|
|
'company_id',
|
|
'username',
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'phone',
|
|
'avatar',
|
|
'role',
|
|
'status',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var array<int, string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be cast.
|
|
*
|
|
* @var array<string, string>
|
|
*/
|
|
protected $casts = [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
|
|
/**
|
|
* Get the login logs for the user.
|
|
*/
|
|
public function loginLogs()
|
|
{
|
|
return $this->hasMany(\App\Models\UserLoginLog::class);
|
|
}
|
|
|
|
/**
|
|
* Get the company that owns the user.
|
|
*/
|
|
public function company()
|
|
{
|
|
return $this->belongsTo(Company::class);
|
|
}
|
|
|
|
/**
|
|
* Check if the user is a system administrator.
|
|
*/
|
|
public function isSystemAdmin(): bool
|
|
{
|
|
return is_null($this->company_id);
|
|
}
|
|
|
|
/**
|
|
* Check if the user belongs to a tenant.
|
|
*/
|
|
public function isTenant(): bool
|
|
{
|
|
return !is_null($this->company_id);
|
|
}
|
|
|
|
/**
|
|
* Get the URL for the user's avatar.
|
|
*/
|
|
public function getAvatarUrlAttribute(): string
|
|
{
|
|
if ($this->avatar) {
|
|
return \Illuminate\Support\Facades\Storage::disk('public')->url($this->avatar);
|
|
}
|
|
|
|
// Return a default UI Avatar if no avatar is set
|
|
return "https://ui-avatars.com/api/?name=" . urlencode($this->name) . "&color=7F9CF5&background=EBF4FF";
|
|
}
|
|
}
|