---
title: "Expirations — Connections for Laravel | Roundly"
description: "Give connections an expiry, move or clear it, set a default window, and see how expiry affects access checks."
url: https://roundly-consulting.com/open-source/docs/connections-for-laravel/expirations
language: en
---

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

[Connections for Laravel](https://roundly-consulting.com/open-source/docs/connections-for-laravel.md)

# Expirations

A connection can carry an optional expires\_at. Stage it on the builder or pass it to connectTo():

```php
use Carbon\CarbonInterval;
use RoundlyConsulting\Connections\Facades\Connections;

Connections::between($user, $team)->expiresIn(now()->addMonth())->connect();        // an instant
Connections::between($user, $team)->expiresIn(CarbonInterval::days(14))->connect(); // an interval from now
Connections::between($user, $team)->expiresIn(3600)->connect();                     // seconds from now
Connections::between($user, $team)->expiringAt(now()->addYear())->connect();        // an exact instant, or null

$user->connectTo($team, ['view'], now()->addWeek());
```

## Moving the expiry

```php
Connections::between($user, $team)->extend(now()->addYear());   // move the expiry
Connections::between($user, $team)->extend(null);               // clear it — never expires

$connection->expires_at;   // ?CarbonInterface
$connection->isExpired();  // expires_at is in the past
$connection->isActive();   // accepted and not expired
```

extend() throws ConnectionNotFound when there is no connection, and fires ConnectionUpdated.

## Default expiry

Set expiry.default to give new connections an expiry when the caller supplies none — a positive relative string such as 30 days or 2 weeks, or at least 1 second as an integer or a numeric env string; anything else throws InvalidConfigurationException. It applies to new connections only: re-connecting an existing pair keeps its stored expiry. An explicit expiry always wins; null (the default) or a blank value means connections never expire unless you say so:

```php
// config/connections.php
'expiry' => [
    'default' => '30 days',   // or an integer of seconds, e.g. 2592000
],
```

## What expiry does

- isExpired() is true once expires\_at is in the past; isActive() is true for an accepted connection that hasn’t expired.
- connect() on an existing pair keeps its expiry unless you stage a new one, and toggle() never renews one — renew with extend(), clear with extend(null).
- While enforce\_active\_on\_check is on, an expired connection grants no permissions and doesn’t count for isConnectedTo() — even before it is pruned.
- Expired rows stay in the table until you prune them with connections:prune, Connections::prune() or model:prune (see Artisan commands).
- connections:notify-expiring dispatches ConnectionExpiring for connections about to lapse.
- The expiredConnections() and expiringConnections() relations list them per model (see Querying connections); Connections::expiring($days) queries every live connection expiring within the window, across all connectors.

## 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/connections-for-laravel.md)
