*/ protected $fillable = [ 'company_id', 'username', 'name', 'email', 'password', 'phone', 'avatar', 'role', 'status', 'is_admin', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'is_admin' => 'boolean', ]; /** * Get the login logs for the user. */ public function loginLogs() { return $this->hasMany(UserLoginLog::class); } /** * Get the company that owns the user. */ public function company() { return $this->belongsTo(Company::class); } /** * Get the machines assigned to the user. */ public function machines() { return $this->belongsToMany(\App\Models\Machine\Machine::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"; } }