tinyurl

A Simple Laravel URL Shortener Package.

Introduction

A custom user friendly URL shortener where user can modify the requirements effortlessly. URL's will be prefixed by your domain name and a custom made prefix.

Use


 use Sadaimudinaadhar\Tinyurl\Facades\TinyUrl;

 $short_url = TinyUrl::create("https://github.com/sadaimudiNaadhar/tinyurl"); 
 print $short_url;    //  https://YOUR_DOMAIN/v1/asXy 

Note User can modify the prefix 'v1' and can also set the length of tinyurl.

Installation

- Run below Composer command


   composer require sadaimudinaadhar/tinyurl 

- Publish migrations (OPTIONAL) and configuration files.


php artisan vendor:publish --tag=tinyurlconfig // Publishes tinyurls.php in your config folder.   
php artisan vendor:publish --tag=tinyurlmigration // Publishes migrations in your database/migrations

Note Migrations will be automatically loaded. If you want to publish run the above migration command.

- Run the migration.

Note Before running the migration, if you want to change table name. please do change in config/tinyurls.php. By default table name will be tiny_urls.


php artisan migrate

Configurations

User can override default configurations in file config/tinyurls.php


'TABLE' => 'tiny_urls',
'URL_PREFIX' => 'v1',
'MIN_LENGTH' => 4,
'USE_NUMBERS' => true,
'AUTH_URL_ROUTES' => false,

Troubleshooting

If you are using lower version of Laravel (Below 5.5). Register below alias and ServiceProvider manually in config/app.php


  'providers' => [ 
        /*
         * Package Service Providers...
         */

       Sadaimudinaadhar\Tinyurl\Providers\TinyUrlServiceProvider::class,
     ],
 'aliases' => [

        'TinyUrl' => Sadaimudinaadhar\Tinyurl\Facades\TinyUrl::class

    ],