'Habilitado', self::STATUS_DISABLED => 'Deshabilitado', self::STATUS_REMOVED => 'Eliminado', ]; /** * List of names for each status. * @var array */ public static $statusListClass = [ self::STATUS_ENABLED => 'success', self::STATUS_DISABLED => 'warning', self::STATUS_REMOVED => 'danger', ]; /** * The attributes that are mass assignable. * * @var array */ protected $fillable = [ 'name', 'last_name', 'email', 'password', 'profile_photo_path', 'status', 'created_by', ]; /** * The attributes that should be hidden for serialization. * * @var array */ protected $hidden = [ 'password', 'remember_token', 'two_factor_recovery_codes', 'two_factor_secret', ]; /** * The accessors to append to the model's array form. * * @var array */ protected $appends = [ 'profile_photo_url', ]; /** * Nombre de la etiqueta para generar Componentes * * @var string */ public $tagName = 'User'; /** * Nombre de la columna que contiee el nombre del registro * * @var string */ public $columnNameLabel = 'full_name'; /** * Nombre singular del registro. * * @var string */ public $singularName = 'usuario'; /** * Nombre plural del registro. * * @var string */ public $pluralName = 'usuarios'; /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'email_verified_at' => 'datetime', 'password' => 'hashed', ]; } /** * Attributes to include in the Audit. * * @var array */ protected $auditInclude = [ 'name', 'email', ]; /** * Get the full name of the user. * * @return string */ public function getFullnameAttribute() { return trim($this->name . ' ' . $this->last_name); } /** * Get the initials of the user's full name. * * @return string */ public function getInitialsAttribute() { return self::getInitials($this->fullname); } /** * Envía la notificación de restablecimiento de contraseña. * * @param string $token */ public function sendPasswordResetNotification($token) { // Usar la notificación personalizada $this->notify(new CustomResetPasswordNotification($token)); } /** * Obtener usuarios activos con una excepción para incluir un usuario específico desactivado. * * @param array $filters Filtros opcionales como ['type' => 'user', 'status' => 1] * @param int|null $includeUserId ID de usuario específico a incluir aunque esté inactivo * @return array */ public static function getUsersListWithInactive($includeUserId = null, array $filters = []): array { $query = self::query(); // Filtro por tipo de usuario dinámico $tipoUsuarios = [ 'partner' => 'is_partner', 'employee' => 'is_employee', 'prospect' => 'is_prospect', 'customer' => 'is_customer', 'provider' => 'is_provider', 'user' => 'is_user', ]; if (isset($filters['type']) && isset($tipoUsuarios[$filters['type']])) { $query->where($tipoUsuarios[$filters['type']], 1); } // Filtrar por estado o incluir usuario inactivo $query->where(function ($q) use ($filters, $includeUserId) { if (isset($filters['status'])) { $q->where('status', $filters['status']); } if ($includeUserId) { $q->orWhere('id', $includeUserId); } }); return $query->pluck(\DB::raw("CONCAT(name, ' ', IFNULL(last_name, ''))"), 'id')->toArray(); } /** * User who created this user */ public function creator() { return $this->belongsTo(self::class, 'created_by'); } /** * Check if the user is active */ public function isActive() { return $this->status === self::STATUS_ENABLED; } }