Short URL Package for Laravel Applications
Published on by Paul Redmond
Short URL by Ash Allen is a Laravel package for creating shortened URLs in your Laravel applications. You can easily create a new short URL with the following code to get started:
use AshAllenDesign\ShortURL\Classes\Builder; $builder = new Builder(); $shortURLObject = $builder->destinationUrl('https://destination.com')->make();$shortURL = $shortURLObject->default_short_url;
It's up to you to configure and build short URLs around your existing data; for example, you could generate a short URL when a new post model is published.
This package provides all the basics and a bunch of advanced features to start creating short, sharable URLs for your apps. Its main features include:
- Custom URL Keys
- Single-use short URLs
- Enforce HTTPS
- Configure redirect status code (302 found instead of 301 permanent)
- Make a short URL active and inactive on a certain date
- Track Visitors:
- IP Address
- Browser Name
- Browser Version
- Operating System Name
- Operating System Version
- Referrer URL (the URL that the visitor originally came from)
- Device Type (can be: desktop/mobile/tablet/robot)
Here are more examples of working with existing ShortURL model instances from the README:
use \AshAllenDesign\ShortURL\Models\ShortURL; // Find URL by key$shortURL = ShortURL::findByKey('abc123'); // Find by destination$shortURLs = ShortURL::findByDestinationURL('https://destination.com'); // Enable tracking to an existing short URL instance$shortURL->trackingEnabled(); // Get model properties, such as visits$shortURL = ShortURL::find(1);$visits = $shortURL->visits; // Single-use short URL$builder = new \AshAllenDesign\ShortURL\Classes\Builder(); $shortURLObject = $builder ->destinationUrl('https://destination.com') ->singleUse() ->make();
Learn More
You can learn more about this package, get full installation instructions, and view the source code on GitHub. The README contains complete documentation with everything you need to set up and start interacting with short URLs.