final class Auth

Static entry point to the application's auth guard. Lazily constructs a single SessionGuard so every caller shares one resolved user per request, and forwards the common guard operations (check, user, id) to it. A guard may also be injected via setGuard() to support testing.

Constants

DEFAULT_USER_MODEL

The user model used when config/auth.php does not set user_model.

Properties

static private Guard|null $guard

The shared guard instance for the current request, or null until first constructed.

Methods

static bool
check()

Determines whether a user is currently authenticated.

static Guard
guard()

Returns the shared guard, constructing it on first use.

static mixed
id()

Gets the identifier of the currently authenticated user.

static void
setGuard(Guard|null $guard)

Sets the shared guard instance, replacing any existing one. Intended primarily for testing, where a guard backed by a fake provider or session can be injected. Passing null resets the guard so the next call to guard() constructs a fresh default instance.

static Principal|null
user()

Gets the currently authenticated user.

static string
userModel()

Resolves the application's user model class. Framework code uses this instead of importing App\Models\Users so Core does not depend on the application. Reads auth.user_model from config/auth.php and falls back to App\Models\Users.

Details

at line 37
static bool check()

Determines whether a user is currently authenticated.

Return Value

bool

True if a user is authenticated, otherwise false.

at line 44
static Guard guard()

Returns the shared guard, constructing it on first use.

Return Value

Guard

at line 59
static mixed id()

Gets the identifier of the currently authenticated user.

Return Value

mixed

The authenticated user's identifier, or null if no user is authenticated.

at line 73
static void setGuard(Guard|null $guard)

Sets the shared guard instance, replacing any existing one. Intended primarily for testing, where a guard backed by a fake provider or session can be injected. Passing null resets the guard so the next call to guard() constructs a fresh default instance.

Parameters

Guard|null $guard

The guard to use, or null to reset.

Return Value

void

at line 83
static Principal|null user()

Gets the currently authenticated user.

Return Value

Principal|null

The authenticated user, or null if no user is authenticated.

at line 97
static string userModel()

Resolves the application's user model class. Framework code uses this instead of importing App\Models\Users so Core does not depend on the application. Reads auth.user_model from config/auth.php and falls back to App\Models\Users.

Return Value

string

The fully qualified user model class.

Exceptions

FrameworkRuntimeException