# WHMCS\User\AdminLog

`Class` · extends `AbstractModel`

An administrative user login

Each log entry in this table represents a single login session for an
administrative user.

## Constants

| Name | Description |
|  --- | --- |
| `ONLINE_WINDOW_MINUTES` | The number of minutes since a visit within which an admin user is still considered to be online. |


## Properties

| Type | Name | Description |
|  --- | --- | --- |
| `` | `$timestamps` |  |
| `` | `$unique` |  |


## Methods

### getOnlineCutOff

```php
public static function getOnlineCutOff(): string
```

The time before which a visit no longer counts as being online.

Deliberately evaluated in PHP rather than with the database's NOW(),
because every lastvisit value is written by PHP: update_query() and
insert_query() expand "now()" to date('YmdHis') rather than passing it
to the database. Comparing PHP written values against the database clock
would make admin users permanently online, or permanently offline,
wherever the two time zones differ.

**Returns** `string` — A "Y-m-d H:i:s" time.

### admin

```php
public function admin()
```

An admin log entry belongs to an admin user.

**Returns** `\Illuminate\Database\Eloquent\Relations\belongsTo`

### scopeOnline

```php
public function scopeOnline($query)
```

Retrieve the most recent open session of every admin user who is online.

Selects one deterministic row per admin user - the highest id - rather
than grouping the outer query, which under a permissive sql_mode returns
an arbitrary row from each group and under ONLY_FULL_GROUP_BY errors.

The open session constraint is repeated on the outer query deliberately.
MySQL materialises this IN rather than rewriting it into a semijoin, so
without it the outer query carries no predicate and scans the whole of a
table that is never pruned. Repeating it restores an index range scan,
and cannot change the result set: every id the subquery yields belongs
to a row that already satisfies the constraint.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `\Illuminate\Database\Eloquent\Builder` | `$query` |  |


**Returns** `\Illuminate\Database\Eloquent\Builder`

### constrainToOpenSessions

```php
public static function constrainToOpenSessions($query)
```

Narrow a tbladminlog query to the sessions that are still open, meaning
visited inside the online window and not yet logged out.

Held here so that the scopes on this model and the staff presence
repository agree on the window and on the zero date standing in for
"still logged in". It is not the only place that knowledge lives: the
legacy admin log screen and the GetStaffOnline and GetStats endpoints
still spell the zero date out themselves, in three different literals.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `\Illuminate\Database\Query\Builder|\Illuminate\Database\Eloquent\Builder` | `$query` |  |


**Returns** `\Illuminate\Database\Query\Builder\|\Illuminate\Database\Eloquent\Builder`

### scopeOffline

```php
public function scopeOffline($query)
```

Retrieve the log entries of every admin user who is not currently online.

**Parameters**

| Type | Name | Description |
|  --- | --- | --- |
| `\Illuminate\Database\Eloquent\Builder` | `$query` |  |


**Returns** `\Illuminate\Database\Eloquent\Builder`

### getLastVisitFormattedAttribute

```php
public function getLastVisitFormattedAttribute(): string
```