PHPackages                             roddy/url-shortener - 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. roddy/url-shortener

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

roddy/url-shortener
===================

A Laravel package for creating shortened URLs with QrCode for your web apps.

1.0.0(3y ago)41.7k↓86.9%MITPHPPHP ^8.0

Since Jun 21Pushed 2mo ago1 watchersCompare

[ Source](https://github.com/Freddywhest/url-shortener)[ Packagist](https://packagist.org/packages/roddy/url-shortener)[ Docs](https://github.com/Freddywhest/url-shortener)[ RSS](/packages/roddy-url-shortener/feed)WikiDiscussions main Synced 2w ago

READMEChangelog (1)Dependencies (1)Versions (5)Used By (0)

[![Packagist Downloads](https://camo.githubusercontent.com/a4bfb613972ce8691abba91838151eff8bdfefebc37f8463af0f57e7b8105eb1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6464792f75726c2d73686f7274656e6572)](https://camo.githubusercontent.com/a4bfb613972ce8691abba91838151eff8bdfefebc37f8463af0f57e7b8105eb1/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f726f6464792f75726c2d73686f7274656e6572)

Table of Contents
-----------------

[](#table-of-contents)

- [Overview](#overview)
- [Installation](#installation)
    - [Requirements](#requirements)
    - [Install the Package](#install-the-package)
    - [Publish the Config and Migrations](#publish-the-config-and-migrations)
    - [Migrate the Database](#migrate-the-database)
- [Usage](#usage)
    - [Generating Shortened URLs](#generating-shortened-urls)
        - [Quick Start](#start)
        - [Domain for the Shortened URL](#Domain-for-the-Shortened-URL)
        - [Custom Keys](#custom-keys)
        - [Set User id](#user-id)
        - [Schedule when the url can be access](#Schedule-when-the-url-can-be-access)
        - [Generate a QrCode Image for Short Url](#Generate-a-QrCode-Image-for-Short-Url)
        - [Generate a QrCode Svg for Short Url](#Generate-a-QrCode-Svg-for-Short-Url)
        - [Rules for Generating Shortened URLs](#Rules-for-Generating-Shortened-URLs)
    - [Retrieving Url](#Retrieving-Url)
        - [Find by Id](#find-by-id)
        - [Find by URL Key](#find-by-url-key)
        - [Find by Original URL](#find-by-original-url)
        - [Find Where](#find-where)
        - [Get all URLs](#get-all-urls)
    - [Deleteing Url](#Deleteing-Url)
        - [Delete by id](#delete-by-id)
        - [Delete by URL Key](#delete-by-url-key)
        - [Delete by Original URL](#delete-by-original-url)
        - [Delete Where](#delete-where-url)
    - [Get Instance of Model](#model-factories)
        - [urlShortenerDB](#urlShortenerDB)
- [Security](#security)
- [Credits](#credits)
- [License](#license)

Overview
--------

[](#overview)

A Laravel package that can be used for adding shortened URLs to your existing web app.

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

[](#installation)

Quick note: You must have a basic understanding of the use of the artisan command and composer for installing laravel package.

### Requirements

[](#requirements)

The package has been developed and tested to work with the following minimum requirements:

- PHP &gt;= 8.0
- Laravel &gt;= 8.0

### Install the Package

[](#install-the-package)

You can install the package via Composer:

```
composer require roddy/url-shortener
```

### Publish the Config and Migrations

[](#publish-the-config-and-migrations)

You can then publish the package's config file and database migrations by using the following command:

```
php artisan vendor:publish --provider="Roddy\UrlShortener\UrlShortenerProvider"
```

### Migrate the Database

[](#migrate-the-database)

This package contains a migration that add a new table to the database: `url_shortener`. To run this migration, simply run the following command:

```
php artisan migrate
```

Usage
-----

[](#usage)

### Generating Shortened URLs

[](#generating-shortened-urls)

#### Start

[](#start)

There are two(2) ways to start using url-shortener

- [Generate Shortened Url and Store it into the Database](#generate-shortened-url-and-store-it-into-the-database)
- [Generate Shortened Url Without Storing it into the Database](#generate-shortened-url-without-storing-it-into-the-database)

###### Generate Shortened Url and Store it into the Database

[](#generate-shortened-url-and-store-it-into-the-database)

To store a generated shortened url, you need to add the `store` method.

For example:

```
   use Roddy\UrlShortener\UrlShortenerGenerator;
   UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                           ->store()
                           ->generate();
```

###### Generate Shortened Url Without Storing it into the Database

[](#generate-shortened-url-without-storing-it-into-the-database)

To not store a generated shortened url, you do not need to add the `store` method.

For example:

```
   use Roddy\UrlShortener\UrlShortenerGenerator;
   UrlShortenerGenerator::originalUrl('https://orginalurl.com')->generate();
```

#### Domain for the Shortened URL

[](#domain-for-the-shortened-url)

By default the domain for the shortened url will be the current domain of the website. For example if the domain for your website is , your shortened url will use  as the domain. You can change it by setting the `domain` in `config/urlshortener.php` to the domain you want.

#### Custom Keys

[](#custom-keys)

By default, the shortened URL that is generated will contain a random url key. The url key will be of the length that you define in the config files (defaults to 7 characters). Config file can be found in `config/urlshortener.php`. Example: if a URL is `https://domain/aBc1234`, the key is `aBc1234`.

You may wish to define a custom url key for your shortened url rather than generating a random key. You can do this by using the `->customKey()` method.

Examples:

1. This example will store the generated shortened url with the custom key into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->customKey("custom-url-key") //param should be a string
                            ->store()
                            ->generate();
    // Short URL: https://domain.com/custom-key
```

2. This example will generated a shortened url with the custom key without storing it into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->customKey("custom-url-key") //param should be a string
                            ->generate();
    // Short URL: https://domain.com/custom-key
```

#### User id

[](#user-id)

Urlshortener allows you to add a user id to the generated short url to indicate the user that generated it. By default it is `null`, you can add a user id by using the `->byUerId()` method.

Examples:

1. This example will store the generated shortened url with the user id into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->byUserId(1) //param should be a string or int
                            ->store()
                            ->generate();
```

2. This example will generated a shortened url with the user id without storing it into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->byUserId(1) //param should be a string or int
                            ->generate();
```

#### Schedule when the url can be access

[](#schedule-when-the-url-can-be-access)

By default, all short URLs that you generate can be access on the day you generated it. However, you may set a date for accessing your URLs when you're generating them. You can do this by using the `->schedule()` method. The `->schedule()` method accepts number of days as the parameter and it must be `int`.

Exapmles:

1. This example will store the generated shortened url with the schedule date into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->schedule(2) //This will schedule it to the next 2 days
                            ->store()
                            ->generate();
```

2. This example will generated a shortened url with the schedule date without storing it into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->schedule(2) //This will schedule it to the next 2 days
                            ->generate();
```

#### Generate a QrCode Image for Short Url

[](#generate-a-qrcode-image-for-short-url)

You can generate a QrCode image for your short url by using the `->generateQrCodeImage()` method. Note: This method generate an image url for the QrCode, example of the image url `data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAKUAAAClCAIAAACyS`. Note: You can not use `->generateQrCodeSvg()` and `->generateQrCodeImage()` at the same time, you have to use only one of them.

Examples of usage:

1. This example will store the generated shortened url with the generated QrCode Image into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->generateQrCodeImage() //add this method
                            ->store()
                            ->generate();
```

2. This example will generated a shortened url with the generated QrCode Image without storing it into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->generateQrCodeImage() //add this method
                            ->generate();
```

#### Generate a QrCode Svg for Short Url

[](#generate-a-qrcode-svg-for-short-url)

You can generate a QrCode svg for your short url by using the `->generateQrCodeSvg()` method. Note: You can not use `->generateQrCodeSvg()` and `->generateQrCodeImage()` at the same time, you have to use only one of them.

Examples of usage:

1. This example will store the generated shortened url with the generated QrCode Svg into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->generateQrCodeSvg() //add this method
                            ->store()
                            ->generate();
```

2. This example will generated a shortened url with the generated QrCode Svg without storing it into the database;

```
    use Roddy\UrlShortener\UrlShortenerGenerator;
    UrlShortenerGenerator::originalUrl('https://orginalurl.com')
                            ->generateQrCodeSvg() //add this method
                            ->generate();
```

#### Rules for Generating Shortened URLs

[](#rules-for-generating-shortened-urls)

1. You can not use `->generateQrCodeSvg()` and `->generateQrCodeImage()` at the same time, you have to use only one of them.
2. The `->generate()` method should always be the last method.
3. The `->schedule()` method accepts only int/number as the days parameter.

### Retrieving Url

[](#retrieving-url)

#### Find by Id

[](#find-by-id)

To find the ShortURL model that corresponds to a given shortened URL id, you can use the `findById()` method.

For example, to find the ShortURL model of a shortened URL that has the id `1`, you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::findById(1);
```

#### Find by URL Key

[](#find-by-url-key)

To find the ShortURL model that corresponds to a given shortened URL key, you can use the `findByKey()` method.

For example, to find the ShortURL model of a shortened URL that has the key `aBcD234`, you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::findByKey('aBcD234');
```

#### Find by Original URL

[](#find-by-original-url)

To find the ShortURL model that corresponds to a given shortened URL original Url, you can use the `findByOriginalUrl()` method.

For example, to find all of the ShortURL models of shortened URLs with original url of `https://originalUrl.com`, you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::findByOriginalUrl("https://destination.com");
```

#### Find Where

[](#find-where)

To find the ShortURL model that corresponds to a given custom query or filter, you can use the `findWhere()` method.

For example, to find all shortened url `where id is greater than 1` you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::findWhere("id", ">", "1");
```

**Note**: the `findWhere()` method takes 3 parameters, which are `column, opertor, value`, you can set the `oprator` parameter to `null` if you don't want to provide an `operator`. Example:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::findWhere("id", null, "1");
```

#### Get all URLs

[](#get-all-urls)

To get all Shortened URL, you can use the `getAll()` method.

Example:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::getAl);
```

### Deleteing Url

[](#deleteing-url)

**Note:** All the delete methods returns an array.

#### Delete by id

[](#delete-by-id)

To delete the ShortURL model that corresponds to a given shortened URL id, you can use the `deleteById()` method.

For example, to delete the ShortURL model of a shortened URL that has the id `1`, you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::deleteById(1);
```

#### Delete by URL Key

[](#delete-by-url-key)

To delete the ShortURL model that corresponds to a given shortened URL key, you can use the `deleteByKey()` method.

For example, to delete the ShortURL model of a shortened URL that has the key `aBcD234`, you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::deleteByKey('aBcD234');
```

#### Delete by Original URL

[](#delete-by-original-url)

To delete the ShortURL model that corresponds to a given shortened URL original url, you can use the `deleteByOriginalUrl()` method.

For example, to delete the ShortURL model of a shortened URL that has the original url `https://originalUrl.com`, you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::deleteByOriginalUrl('https://originalUrl.com');
```

#### Delete Where

[](#delete-where)

To delete the ShortURL model that corresponds to a given custom query or filter, you can use the `deleteWhere()` method.

For example, to delete all shortened url `where id is greater than 1` you could use the following:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::deleteWhere("id", ">", "1");
```

**Note**: the `deleteWhere()` method takes 3 parameters, which are `column, opertor, value`, you can set the `oprator` parameter to `null` if you don't want to provide an `operator`. Example:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = UrlShortenerModel::deleteWhere("id", null, "1");
```

### Get Instance of Model

[](#get-instance-of-model)

#### urlShortenerDB

[](#urlshortenerdb)

urlShortenerDB returns the urlShortener Model which allows you to use all the `Eloquent` methods provided by Laravel. To see the Eloquent methods click here or visit .

Example of Usage:

```
use Roddy\UrlShortener\Model\UrlShortenerModel
$shortURL = urlShortenerDB::findOrFail(1); //You can use any of the Eloquent query building
```

Security
--------

[](#security)

If you find any security related issues, please contact me directly at  to report it.

Contribution
------------

[](#contribution)

If you wish to make any changes or improvements to the package, feel free to make a pull request.

Credits
-------

[](#credits)

- [Alfred Nti](https://github.com/Freddywhest)
- [Chillerlan](https://github.com/chillerlan) (QrCode Generator)
- [All Contributors](https://github.com/Freddywhest/url-shortener/graphs/contributors)

License
-------

[](#license)

The MIT License (MIT). Please see [License File](LICENSE.md) for more information.

###  Health Score

38

—

LowBetter than 83% of packages

Maintenance57

Moderate activity, may be stable

Popularity23

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity53

Maturing project, gaining track record

 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

Unknown

Total

1

Last Release

1155d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/7106eb034822aaece5eb5521fdb0d92ce844323ea41c11b16c162bcbd9a48cf1?d=identicon)[roddy](/maintainers/roddy)

---

Top Contributors

[![Freddywhest](https://avatars.githubusercontent.com/u/87778148?v=4)](https://github.com/Freddywhest "Freddywhest (5 commits)")

---

Tags

composer-librarycomposer-packagelaravellaravel-shortlaravel-shortyphp-short-urlqrcode-generatorshortenershortener-packageshortnerurlurl-shortener

### Embed Badge

![Health badge](/badges/roddy-url-shortener/health.svg)

```
[![Health](https://phpackages.com/badges/roddy-url-shortener/health.svg)](https://phpackages.com/packages/roddy-url-shortener)
```

###  Alternatives

[appwrite/server-ce

End to end backend server for frontend and mobile apps.

56.9k115.4k](/packages/appwrite-server-ce)[filament/filament

A collection of full-stack components for accelerated Laravel app development.

3932.5M4.4k](/packages/filament-filament)[kriansa/openboleto

Biblioteca para geração de boletos bancários.

6092.2M2](/packages/kriansa-openboleto)[salla/zatca

A helper to generate the QR code and signed it for ZATCA e-invoicing

165463.2k2](/packages/salla-zatca)[abydahana/aksara

Aksara is a modern, developer-friendly framework and CMS built on CodeIgniter 4, featuring rapid CRUD development, modular architecture, smart routing, flexible access control, API integration, and an AI assistant to make content management faster and smarter.

1141.2k](/packages/abydahana-aksara)[skeeks/cms-shop

Интернет магазин для SkeekS CMS

145.9k25](/packages/skeeks-cms-shop)

PHPackages © 2026

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