NewWe open-sourced 50+ Laravel packages
Custom AI apps, agents and automation — Roundly ConsultingRoundly
All packages
Connections for Laravel

Artisan commands

The package registers three commands:

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
CommandWhat it does
connections:pruneSoft-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:

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 — and a block goes with its row.

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:

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

// 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

By donating, you agree to our donation terms.

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.