承接 badmushroom/shorties 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

badmushroom/shorties

Composer 安装命令:

composer require badmushroom/shorties

包简介

A simple URL shortner for Laravel applications.

README 文档

README

shorties_logo_transparent_512x512

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

统计信息

  • 总下载量: 3
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 0
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 1
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-04-06