Skip to main content

UserStatus Enum

The UserStatus enum defines the account status for users and other entities in the OPBX system.

Definition

namespace App\Enums;

enum UserStatus: string
{
case ACTIVE = 'active';
case INACTIVE = 'inactive';
}

Values

ValueLabelDescription
activeActiveAccount is enabled and can access the system
inactiveInactiveAccount is disabled and cannot access the system

Methods

label(): string

Get human-readable label.

UserStatus::ACTIVE->label();   // "Active"
UserStatus::INACTIVE->label(); // "Inactive"

isActive(): bool

Check if status is active.

if ($user->status->isActive()) {
// Allow login
}

isInactive(): bool

Check if status is inactive.

if ($user->status->isInactive()) {
// Deny access
}

Usage Example

use App\Enums\UserStatus;
use App\Models\User;

// Create active user
$user = User::create([
'name' => 'John Doe',
'email' => 'john@example.com',
'status' => UserStatus::ACTIVE,
]);

// Check before allowing access
if ($user->status->isActive()) {
// Process login
}

// Deactivate user
$user->update(['status' => UserStatus::INACTIVE]);

// Reactivate user
$user->update(['status' => UserStatus::ACTIVE]);

Database Storage

Stored as VARCHAR(50) in the database:

status VARCHAR(50) NOT NULL DEFAULT 'active'

Used By