*/ protected $fillable = [ 'first_name', 'last_name', 'email', 'password', 'role_id', 'tfa_secret', 'email_verified_at', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'tfa_secret', ]; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', 'tfa_secret' => 'encrypted', ]; } /** * Initials of the user. * * @return string */ public function initials(): Attribute { return Attribute::make( get: fn () => strtoupper(substr($this->first_name, 0, 1) . substr($this->last_name, 0, 1)), ); } /** * Avatar URL for the user. * * @return string */ public function avatar(): Attribute { return Attribute::make( get: fn () => 'https://www.gravatar.com/avatar/' . md5(strtolower($this->email)) . '?d=' . urlencode((string) config('settings.gravatar_default')), ); } public function getFilamentAvatarUrl(): ?string { return $this->avatar; } /** * Get the display name for the user. * * @return string */ public function name(): Attribute { return Attribute::make( get: fn () => ($this->first_name . ' ' . $this->last_name) ?: $this->email, ); } public function hasPermission($permission): bool { if (is_null($this->role)) { return false; } // If the user has all permissions, return true if (in_array('*', $this->role->permissions)) { return true; } return in_array($permission, $this->role->permissions); } /** Relationships */ /** * Get the role that the user belongs to. * Can be null if the user is a normal user (non-admin). */ public function role() { return $this->belongsTo(Role::class); } /** * Get the user's sessions. */ public function sessions() { return $this->hasMany(Session::class); } /** * Get the user's orders. */ public function orders() { return $this->hasMany(Order::class); } /** * Get the user's services */ public function services() { return $this->hasMany(Service::class); } /** * Get the user's invoices. */ public function invoices() { return $this->hasMany(Invoice::class); } public function canAccessPanel(Panel $panel): bool { if ($panel->getId() === 'admin') { return !is_null($this->role); } return false; } /** * Get the user tickets */ public function tickets() { return $this->hasMany(Ticket::class); } /** * Get the user's credits */ public function credits() { return $this->hasMany(Credit::class); } public function cart() { return $this->hasOne(Cart::class); } public function billingAgreements() { return $this->hasMany(BillingAgreement::class); } public function transactions() { return $this->hasManyThrough(InvoiceTransaction::class, Invoice::class, 'user_id', 'invoice_id', 'id', 'id'); } public function notifications() { return $this->hasMany(Notification::class); } public function notificationsPreferences() { return $this->hasMany(NotificationPreference::class); } public function pushSubscriptions() { return $this->hasMany(NotificationSubscription::class); } public function authenticationLogs() { return $this->hasMany(UserAuthenticationLog::class); } }