PHPackages                             bradietilley/laravel-shortify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bradietilley/laravel-shortify

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bradietilley/laravel-shortify
=============================

Shorten URLs from within Laravel

v0.2.0(1y ago)12MITPHP

Since Oct 26Pushed 1y ago1 watchersCompare

[ Source](https://github.com/bradietilley/laravel-shortify)[ Packagist](https://packagist.org/packages/bradietilley/laravel-shortify)[ RSS](/packages/bradietilley-laravel-shortify/feed)WikiDiscussions main Synced 1mo ago

READMEChangelog (2)Dependencies (6)Versions (3)Used By (0)

Laravel Shortify
================

[](#laravel-shortify)

A simple yet flexible implementation of a URL Shortner in Laravel.

[![Static Analysis](https://github.com/bradietilley/laravel-shortify/actions/workflows/static.yml/badge.svg)](https://github.com/bradietilley/laravel-shortify/actions/workflows/static.yml/badge.svg)[![Tests](https://github.com/bradietilley/laravel-shortify/actions/workflows/tests.yml/badge.svg)](https://github.com/bradietilley/laravel-shortify/actions/workflows/tests.yml/badge.svg)[![Laravel Version](https://camo.githubusercontent.com/8fa27f905a3acd726c18ac953714316a2b5613f5f9e06b5bb2fea1f0fca1fd9f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c25323056657273696f6e2d25453225383925413525323031312e302d463933323243)](https://camo.githubusercontent.com/8fa27f905a3acd726c18ac953714316a2b5613f5f9e06b5bb2fea1f0fca1fd9f/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f4c61726176656c25323056657273696f6e2d25453225383925413525323031312e302d463933323243)[![PHP Version](https://camo.githubusercontent.com/bb92939f358b4888cca839ae31a821eb794bf78469469c4a281e566d81145afb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50485025323056657273696f6e2d254532253839254135253230382e332d344635423933)](https://camo.githubusercontent.com/bb92939f358b4888cca839ae31a821eb794bf78469469c4a281e566d81145afb/68747470733a2f2f696d672e736869656c64732e696f2f62616467652f50485025323056657273696f6e2d254532253839254135253230382e332d344635423933)

Introduction
------------

[](#introduction)

Integrate your own cusom URL shortener into your Laravel App, and track *who* visits *what*!

Installation
------------

[](#installation)

```
composer require bradietilley/laravel-shortify

```

Config and migrations should be published:

```
artisan vendor:publish --tag="shortify-config"
artisan vendor:publish --tag="shortify-migrations"

```

Documentation
-------------

[](#documentation)

### Shortening URLs → Basic usage

[](#shortening-urls--basic-usage)

**Statically:**

You can statically call the `BradieTilley\Shortify\Shortify` singleton to shorten urls:

```
$shortUrl = Shortify::make()->shorten($longUrl)->url; // https://app.com/s/Ws4BYCVLDDDh
$shortUrl = Shortify::url($longUrl)->url; //             https://app.com/s/5wHiKrKx5xV1
```

**Dependency Injection:**

The `BradieTilley\Shortify\Shortify` singleton can be dependency injected:

```
public function handle(Shortify $shortify): void
{
    $url = $shortify->shorten($this->invoice->getSignedUrl());

    echo $url->url; // https://app.com/s/xpLurjDkBATw
}
```

### Shortening URLs → Shortening with an expiry

[](#shortening-urls--shortening-with-an-expiry)

Sometimes your short URLs should be temporary. To achieve this, provide an expiry when shortening.

Viewing an expired URL will result in a `BradieTilley\Shortify\Exceptions\ShortifyExpiredException` exception.

```
$shortUrl = Shortify::make()->shorten($longUrl, expiry: now()->addDay());
$shortUrl = Shortify::url($longUrl, expiry: now()->addDay());
```

### URLs → `ShortifyUrl` Model

[](#urls--shortifyurl-model)

The `BradieTilley\Shortify\Models\ShortifyUrl` model is the map between an original URL and a short URL (unique by code).

**Original URL**

The original URL can be fetched via the `original_url` property

```
$url = Shortify::url($longUrl);
$url->original_url; // same as $longUrl
```

**Shortened URL**

The shortened URL can be fetched via the `url` attribute

```
$url = Shortify::url($longUrl);
$url->url; // https://app.com/s/xpLurjDkBATw
```

The `ShortifyUrl` model overview:

- Fields:
- `id` → auto incrementing ID
- `code` → Unique URL slug/code
- `original_url` → The original URL (text length of 64 KB)
- `visit_count` → A running count of how many times this URL has been visited, for optimised querying (albeit, at the cost of continually updating this field)
- `expired` → Whether or not this URL has expired
- `expires_at` → Timestamp of when this URL expires
- `created_at` → Timestamp of when this URL was created
- `updated_at` → Timestamp of when this URL was updated (which will typically correspond to when it was last visited)
- Attributes:
    - `url` → A computed shortened URL using the code and the current route configuration.
- Relations:
    - `visits` → Has many `ShortifyVisit` models.

### Visits -&gt;`ShortifyVisit` Model

[](#visits--shortifyvisit-model)

The `BradieTilley\Shortify\Models\ShortifyVisit` model represents a unique visit of a shortened url, tracking the user (if authenticated), IP address, and User Agent.

```
$url = ShortifyUrl::findByCode('my-short-url');

$url->visits; // Collection
```

The `ShortifyVisit` model overview:

- Fields:
    - `id` → auto incrementing ID
    - `shortify_url_id` → Foreign Key for `ShortifyUrl`
    - `user_id` → Foreign Key for the visited `User`
    - `ip` → IP Address of visitor
    - `user_agent` → User Agent of visitor
    - `created_at` → Timestamp of when the user visited the URL
- Relations:
    - `user` → The `User` who visited the URL
    - `url` → The `ShortifyUrl` visited

### Customisation → Code Length

[](#customisation--code-length)

The code length defaults to 12, meaning the short URLs are always `https://app.com/s/` followed by 12 alpha-numeric characters such as `50mqV1dfOrth`.

This can be configured via the `shortify.routing.code_length` config variable.

### Customisation → URL Path

[](#customisation--url-path)

The default is `/s/{code}` but in some cases this won't be what you're after.

This can be configured via the `shortify.routing.uri` config variable.

### Customisation → URL Domain

[](#customisation--url-domain)

The default is the default app domain but in some cases you may wish to use an alternative shorthand domain.

Note: You will need to register this other domain and configure the DNS as per usual -- this package does NOT provide *that* type of functionality.

This can be configured via the `shortify.routing.domain` config variable.

### Customisation → Redirect Controller

[](#customisation--redirect-controller)

The default is a rudimentary redirect that is handled by this package, but sometimes you may want to customise how the redirect is handled -- perhaps you want it to be returned in a JSON response that matches how JSON redirects are performed in your app.

This can be configured via the `shortify.routing.route` config variable.

Once configured, the original controller is inaccessible, and you now have full control over the handling of redirects.

### Customisation → Models

[](#customisation--models)

As always with most Laravel packages, you can modify the models to use -- perhaps you want to track more information, add new helpers, etc. No worries.

This can be configured via the `shortify.models.shortify_url` and `shortify.models.shortify_visit` config variables which change the `ShortifyUrl` and `ShortifyVisit` models respectively.

### Customisation → Turn off visitor tracking

[](#customisation--turn-off-visitor-tracking)

Maybe you don't want tracking, or don't need it. Whatever the reasons are, you can disable the tracking of visits setting the `shortify.feature.track_visits` config variable to `false`.

This will prevent the `shortify_urls.visit_count` field from incrementing and will prevent the `shortify_visits` table from being populated.

### Customisation → Everything else

[](#customisation--everything-else)

The `BradieTilley\Shortify\Shortify` singleton can be replaced by another Shortify instance within your service provider. For example:

Extend Shortify:

```
namespace App\Support;

class Shortify extends \BradieTilley\Shortify\Shortify
{
    public function generateCode(ShortifyUrl $url): string
    {
        return Carbon::now()->format('Ymd').'-'.Str::random(6);
    }
}
```

Then register it:

```
$this->app->bind(\BradieTilley\Shortify\Shortify::class, \App\Support\Shortify::class);
```

Then use it:

```
echo Shortify::url($longUrl)->url; // 20241026-TWrCmX
```

Author
------

[](#author)

- [Bradie Tilley](https://github.com/bradietilley)

###  Health Score

21

—

LowBetter than 19% of packages

Maintenance37

Infrequent updates — may be unmaintained

Popularity4

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity30

Early-stage or recently created project

 Bus Factor1

Top contributor holds 100% of commits — single point of failure

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~1 days

Total

2

Last Release

563d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/f93c7d77d882d4106664cca209c6dccc0e531f307f56dc2247937358d193ef0b?d=identicon)[bradietilley](/maintainers/bradietilley)

---

Top Contributors

[![bradietilley](https://avatars.githubusercontent.com/u/44430471?v=4)](https://github.com/bradietilley "bradietilley (24 commits)")

###  Code Quality

TestsPest

Static AnalysisPHPStan

Code StyleLaravel Pint

Type Coverage Yes

### Embed Badge

![Health badge](/badges/bradietilley-laravel-shortify/health.svg)

```
[![Health](https://phpackages.com/badges/bradietilley-laravel-shortify/health.svg)](https://phpackages.com/packages/bradietilley-laravel-shortify)
```

###  Alternatives

[ralphjsmit/laravel-helpers

A package containing handy helpers for your Laravel-application.

13704.6k2](/packages/ralphjsmit-laravel-helpers)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
