short-url
repository·master·Indexed 23 days ago
https://github.com/ash-jc-allen/short-urlA Laravel package for generating, managing, and tracking shortened URLs. It features a fluent Builder class for creating URLs with custom keys, expiration dates, and granular visitor tracking (IP, browser, OS, device type). The package supports custom route structures, single-use URLs, and a beforeCreate callback for adding custom model fields. Requires PHP 8.2, Laravel 10.0, and either the BC Math or GMP extension.
What's inside short-url
- short-url is a Laravel package designed to add shortened URL functionality to an existing web application.
Configure Visitor Tracking
masterTracking is enabled by default. You can override tracking settings for individual URLs during creation using the
Buildermethods.Important: Even if specific fields (like
track_ip_address) are enabled, they will not be recorded unlesstrackVisits()is also enabled (or set totrue).Available Tracking Methods
trackVisits(bool $enabled = true): Enables/disables overall visit recording.trackIPAddress(bool $enabled = true): Enables/disables IP address tracking.trackBrowser(bool $enabled = true): Enables/disables browser name tracking.trackBrowserVersion(bool $enabled = true): Enables/disables browser version tracking.trackOperatingSystem(bool $enabled = true): Enables/disables OS name tracking.trackOperatingSystemVersion(bool $enabled = true): Enables/disables OS version tracking.trackDeviceType(bool $enabled = true): Enables/disables device type tracking.trackRefererURL(bool $enabled = true): Enables/disables referer URL tracking.
// Example: Enabling specific tracking fields use AshAllenDesign\ShortURL\Classes\Builder; $shortURLObject = app(Builder::class) ->destinationUrl('https://destination.com') ->trackVisits() ->trackIPAddress() ->make();Listen for Short URL Visited Events
masterThe package dispatches the
AshAllenDesign\ShortURL\Events\ShortURLVisitedevent every time a short URL is visited.Note on 301 Redirects: If you use a
301(Permanent) redirect status code, browsers may cache the destination and skip the short URL on subsequent visits. This means the event might not fire for repeat visitors. For reliable event dispatching, use a302(Temporary) redirect.Publish migrations for v5.0.0 and later
masterStarting from v5.0.0, Short URL no longer automatically loads database migrations via the service provider. You must manually publish the migrations to your project's
database/migrationsfolder to ensure they are part of your application's migration lifecycle.Run the following command in your project root to publish them:
php artisan vendor:publish --tag="short-url-migrations"Install short-url via Composer
masterInstall the package using Composer to add it to your Laravel project.
composer require ashallendesign/short-urlUpgrade the short-url package
masterTo update this library to a newer version, refer to the officialUPGRADE.mdguide for specific instructions and breaking changes.Quick Start: Building Shortened URLs
masterThe fastest way to create a shortened URL is by using the
Builderclass. The->make()method returns aShortURLmodel instance, from which you can retrieve thedefault_short_urlproperty.use AshAllenDesign\ShortURL\Classes\Builder; $shortURLObject = app(Builder::class) ->destinationUrl('https://destination.com') ->make(); $shortURL = $shortURLObject->default_short_url;Publish configuration and migrations
masterPublish the package's configuration file and database migrations to your application using the Artisan command:
php artisan vendor:publish --provider="AshAllenDesign\ShortURL\Providers\ShortURLProvider"Add activation columns to short_urls table (v3.0.0)
masterShort URL v3.0.0 introduced two new columns to the
short_urlstable:activated_atanddeactivated_at.To apply these changes, run:
php artisan migrateIf you wish to customize the migrations before running them, publish them first using:
php artisan vendor:publish --provider="AshAllenDesign\ShortURL\Providers\ShortURLProvider"Note on Data: When running these migrations, existing short URLs will have today's date automatically populated in the
activated_atcolumn. Thedeactivated_atcolumn will remainnull, meaning existing URLs will remain active indefinitely.Upgrading from 7.* to 8.0.0
masterWhen upgrading to Short URL v8.0.0, note the following breaking changes and requirements:
Minimum Laravel Version
Short URL v8.0.0 requires a minimum of Laravel 8.0.
Minimum PHP Version
Short URL v8.0.0 requires a minimum of PHP 7.3.
Tracking Field Behavior
Undetectable tracking fields are now stored as
nullinstead offalsein the database.Type Safety and Signatures
- Property types have been added to the codebase.
- Several method signatures have changed. Ensure you check your implementations against the new public API.
Upgrading from 5.* to 6.0.0
masterWhen upgrading to Short URL v6.0.0, note the following requirement:
Minimum Laravel Version
Short URL v6.0.0 requires a minimum of Laravel 6.0.
Requirements for short-url
master