badmushroom/shorties
Composer 安装命令:
composer require badmushroom/shorties
包简介
A simple URL shortner for Laravel applications.
关键字:
README 文档
README
Shorties
A Laravel package for generating, managing, and tracking short URLs — complete with analytics, customizable routing, view overrides, and pruning.
🚀 Features
- Generate short URLs with custom or random codes
- Subdomain or path-based routing (configurable)
- Visitor analytics tracking (with fingerprinting, user agent, etc.)
- Optional view override for 404-style "link not found" page
- Artisan commands for creating and listing short links
- Configurable data retention with built-in Laravel pruning support
📦 Installation
composer require badmushroom/shorties
Publish config and views (optional):
php artisan vendor:publish --tag=shorties-config php artisan vendor:publish --tag=shorties-views
Run migrations:
php artisan migrate
⚙️ Configuration
In config/shorties.php, you can configure:
| Key | Description |
|---|---|
route_mode |
subdomain or path |
subdomain |
Subdomain to use for short links (e.g. go) |
prefix |
URI prefix to use if using path mode (e.g. shorties) |
middleware |
Middleware group applied to short URL routes (web, api, etc.) |
track_analytics |
Enable or disable tracking of short URL visits |
analytics_retention_days |
Number of days to keep analytics records before pruning |
Example .env settings
SHORTIES_ROUTE_MODE=path SHORTIES_PATH=shorties SHORTIES_TRACK_ANALYTICS=true SHORTIES_ANALYTICS_RETENTION_DAYS=90
🌐 Routing
Shorties can handle links either by subdomain or by path:
Subdomain-based:
https://go.example.com/my-short-code
Set in config:
'route_mode' => 'subdomain', 'subdomain' => 'go',
Path-based:
https://example.com/shorties/my-short-code
Set in config:
'route_mode' => 'path', 'prefix' => 'shorties',
📊 Analytics Tracking
When track_analytics is enabled, Shorties will dispatch a job on each short link visit that records:
- UUID of the URL
- Timestamp (
visited_at) - User agent
- Fingerprint (if provided)
Records are stored in shorties_analytics.
🧼 Pruning Old Analytics
Shorties supports Laravel's Model Pruning to automatically remove old analytics data.
Add this to your scheduler:
$schedule->command('model:prune')->daily();
Configure retention via:
SHORTIES_ANALYTICS_RETENTION_DAYS=90
Or update config/shorties.php.
You can prune manually with:
php artisan model:prune --model="BadMushroom\Shorties\Models\Analytic"
🛠 Artisan Commands
Create a new short link:
php artisan shorties:links:create
Interactively prompts for a long URL and optional short code.
Admin listing of short links:
php artisan shorties:links
Displays a table of existing short codes, their URLs, visit counts, and creation timestamps.
🎨 Customizing the 404 View
To show a custom “link not found” page, publish the default view:
php artisan vendor:publish --tag=shorties-views
Edit the published file at:
resources/views/vendor/shorties/not-found.blade.php
🔒 Security & Notes
- Uses UUIDs for both URL and analytic IDs
- Tracks analytics only if enabled via config
- Prunes old records based on configurable retention
- Routes are scoped to either a path or subdomain
🧪 Testing
This package includes feature and unit tests. To run them:
vendor/bin/phpunit
🧾 License
This package is open-sourced software licensed under the MIT license.
🤘 Made by Bad Mushroom
badmushroom/shorties 适用场景与选型建议
badmushroom/shorties 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 3 次下载、GitHub Stars 达 0, 最近一次更新时间为 2025 年 04 月 06 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「links」 「URL-Shortener」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 badmushroom/shorties 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 badmushroom/shorties 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 badmushroom/shorties 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Link Field Type for Craft CMS
Set Links with a specific language parameter
Links element Silverstripe
A Laravel package for creating shortened URLs for your web apps.
Laravel package for Enlace2 URL shortener service integration - Complete API wrapper with support for links, QR codes, campaigns, channels, domains, pixels, and overlays
Conversion of inactive links in the text into active clickable links
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 13
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-04-06