• Reading time ~ 1 min
  • 25.08.2022

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.

Comments

No comments yet
Yurij Finiv

Yurij Finiv

Full stack

ABOUT

Professional Fullstack Developer with extensive experience in website and desktop application development. Proficient in a wide range of tools and technologies, including Bootstrap, Tailwind, HTML5, CSS3, PUG, JavaScript, Alpine.js, jQuery, PHP, MODX, and Node.js. Skilled in website development using Symfony, MODX, and Laravel. Experience: Contributed to the development and translation of MODX3 i...

About author CrazyBoy49z
WORK EXPERIENCE
Contact
Ukraine, Lutsk
+380979856297