Projectslaravel-shortifyExtending

Laravel Shortify

Package

URL shortening with visit tracking for Laravel.

Upgrade Guide

Extending

Contracts

Register custom implementations in a service provider:

use BradieTilley\Shortify\Contracts\CodeGenerator;
use BradieTilley\Shortify\Contracts\RedirectsShortUrls;
use BradieTilley\Shortify\Contracts\VisitRecorder;

public function register(): void
{
    $this->app->singleton(CodeGenerator::class, HashidCodeGenerator::class);
    $this->app->singleton(VisitRecorder::class, AnalyticsVisitRecorder::class);
    $this->app->singleton(RedirectsShortUrls::class, PermanentRedirector::class);
}
ContractDefaultUse for
CodeGeneratorRandomCodeGeneratorCustom alphabets, hashids, sequential IDs
VisitRecorderDatabaseVisitRecorderExtra columns, analytics, conditional skips
RedirectsShortUrlsAwayRedirector301 vs 302, headers, custom redirect logic

Subclassing Shortify and re-binding the singleton still works (for example to override generateCode()), but contracts are the preferred extension point.

Models and routes

  • Swap Eloquent models via config/shortify.phpmodels.*
  • Replace the package route via routing.route — see Routing

Soft deletes and code reuse

Soft-deleted rows still occupy their code under the unique index. Force-delete (or prune) before reusing a code.