---
title: "Artisan commands — Connections for Laravel | Roundly"
description: "Prune expired connections, dispatch expiring-soon events, scaffold connectable models, and schedule the maintenance."
url: https://roundly-consulting.com/open-source/docs/connections-for-laravel/commands
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)

# Artisan commands

The package registers three commands:

```bash
php artisan connections:prune                      # soft-delete every expired connection
php artisan connections:notify-expiring --days=7   # dispatch ConnectionExpiring for links expiring within 7 days
php artisan make:connectable Organisation          # scaffold a connectable model
```

| Command | What it does |
| --- | --- |
| `connections:prune` | Soft-delete every expired connection and print the count. |
| `connections:notify-expiring {--days=7}` | Dispatch ConnectionExpiring for each row of Connections::expiring($days) and print the count. |
| `make:connectable {name} {--existing}` | Generate a connectable model, or print the lines to add to an existing one. |

## Pruning expired connections

A connection whose expires\_at is in the past is prunable. connections:prune — and Connections::prune(), which returns the count — soft-deletes every expired connection in one query, so a blocked pair stays blocked and reconnect() can still restore a link. Laravel’s model:prune also works, but differs:

```bash
php artisan model:prune --model="RoundlyConsulting\Connections\Models\Connection"
```

The model is MassPrunable and uses soft deletes, so model:prune permanently deletes expired rows — including rows connections:prune already soft-deleted — except blocked ones: prunable() skips status = blocked, so an expired block survives both prune paths and the pair stays blocked until accept().

## Expiry warnings

connections:notify-expiring dispatches ConnectionExpiring for every connection whose expiry falls within the next --days days (7 by default), with $daysUntilExpiry rounded up. It dispatches one event per row of Connections::expiring($days) and needs no extra table: it fires on every run for each connection still inside the window, whatever its status, so match the window to your schedule — for example a daily run with --days=1. Listen for the event to notify:

```php
use Illuminate\Support\Facades\Event;
use RoundlyConsulting\Connections\Events\ConnectionExpiring;

Event::listen(function (ConnectionExpiring $event): void {
    $connection = $event->connection;

    // AccessExpiringSoon is your own notification class.
    $connection->connector?->notify(
        new AccessExpiringSoon($connection, $event->daysUntilExpiry),
    );
});
```

## Scheduling

```php
// routes/console.php
use Illuminate\Support\Facades\Schedule;

Schedule::command('connections:prune')->daily();
Schedule::command('connections:notify-expiring --days=1')->daily();
```

## make:connectable

make:connectable Organisation generates a model that already uses HasConnections and implements Connectable. With --existing it writes nothing and prints the trait and interface lines to add to a model you already have (see Connectable models).

## 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)
