---
title: "The token model — Refresh Tokens for Laravel | Roundly"
description: "Scopes, helpers, casts and hidden attributes on the RefreshToken model, and how to swap in your own subclass."
url: https://roundly-consulting.com/open-source/docs/refresh-tokens-for-laravel/token-model
language: en
---

[All packages](https://roundly-consulting.com/open-source.md)

[Refresh Tokens for Laravel](https://roundly-consulting.com/open-source/docs/refresh-tokens-for-laravel.md)

# The token model

RoundlyConsulting\\RefreshTokens\\Models\\RefreshToken is a regular Eloquent model with SoftDeletes and Prunable:

```php
use RoundlyConsulting\RefreshTokens\Models\RefreshToken;

RefreshToken::query()->ownedBy($user)->active()->get();     // live sessions
RefreshToken::query()->ownedBy($user)->expired()->count();  // expired rows
RefreshToken::query()->forFamily($familyId)->get();         // every row of one session

$row->isUsable();          // not revoked and not yet expired
$row->sessionStartedAt();  // CarbonImmutable — when the family began
$row->owner;               // MorphTo — the User, Client, …
$row->revoked_reason;      // ?RevocationReason
$row->meta;                // ?array — session metadata
```

- Scopes — active(), expired(), forFamily($id) (lowercases the id) and ownedBy($owner) (morph class and key).
- Helpers — isUsable(), sessionStartedAt() (falls back to created\_at on rows that predate the column) and owner() (MorphTo).
- Casts — expires\_at, revoked\_at, family\_started\_at and absolute\_expires\_at to immutable datetimes; meta to array; is\_bot to boolean; device\_type per device\_type\_cast; revoked\_reason to RevocationReason.
- Hidden — token\_hash and access\_reference.

## Swapping the model

Extend the package model and point refresh-tokens.model at your subclass. A configured class that does not extend the package model falls back to the packaged one:

```php
namespace App\Models;

use RoundlyConsulting\RefreshTokens\Models\RefreshToken as BaseRefreshToken;

class RefreshToken extends BaseRefreshToken
{
    // your own scopes, relations, observers …
}

// config/refresh-tokens.php
'model' => App\Models\RefreshToken::class,
```

## Show your open-source love

This package is free and MIT-licensed. If it saves you time, a one-off donation or a Patreon membership keeps it maintained, tested and documented.

[More ways to support, including crypto](https://roundly-consulting.com/support-us.md)

By donating, you agree to our [donation terms](https://roundly-consulting.com/donation-terms.md).

[Support our open source work (opens in a new tab)](https://donate.stripe.com/dRmeVe8FX5PF1Qd9pXcEw00) [Join us on Patreon (opens in a new tab)](https://www.patreon.com/cw/roundly)

## Want this built into your product?

We integrate our packages into custom Laravel and AI builds. Tell us what you're working on and we'll reply within 48 hours.

[Get a quote in 48 hours](https://roundly-consulting.com/contact.md) [Browse all packages](https://roundly-consulting.com/open-source/docs/refresh-tokens-for-laravel.md)
