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);
}
| Contract | Default | Use for |
|---|---|---|
CodeGenerator | RandomCodeGenerator | Custom alphabets, hashids, sequential IDs |
VisitRecorder | DatabaseVisitRecorder | Extra columns, analytics, conditional skips |
RedirectsShortUrls | AwayRedirector | 301 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.php→models.* - 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.