Short-URL

Short-URL

Short URL Generator { URL, Route }.

Moamen Eltouny (Raggi)
PHP Version : >= 7.2 Laravel Version : >= 6.0 License Support
Source Packagist Version Packagist Downloads

Install

Install the latest version using Composer

composer require pharaonic/laravel-short-url
php artisan migrate

(Optional) To publish the config & migrations.

php artisan vendor:publish --tag=laravel-short-url
Usage

Generate (URL, Route)

Generating a short URL from another URL or Route.

// Generate from URL
shortURL()->generate('https://pharaonic.io');

// Generate from URL with Expiry date (string or Carbon object)
shortURL()->generate('https://pharaonic.io', '2027-07-07');



// Generate from Route
shortURL()->generate('route.name.here', ['param' => 1]);

// Generate from Route with Expiry date (string or Carbon object)
$shortURL = shortURL()->generate('route.name.here', ['param' => 1], '2027-07-07');



// RESULT AS OBJECT
Pharaonic\Laravel\ShortURL\ShortURL { ▼
  ...
  #original: array:7 [▼
    "code" => "97b3b32933"
    "type" => "url"
    "data" => "{"url":"https:\/\/pharaonic.io"}"
    "expire_at" => "2027-07-07 00:00:00"
    "user_id" => null
    "updated_at" => "2020-10-31 07:07:00"
    "created_at" => "2020-10-31 07:07:00"
  ]
  ...
}


// RESULT AS ARRAY
array:7 [▼
  "code" => "97b3b32933"
  "type" => "url"
  "data" => array:1 [▼
    "url" => "https://pharaonic.io"
  ]
  "expire_at" => "2027-07-07T00:00:00.000000Z"
  "user_id" => null
  "updated_at" => "2020-10-31 07:07:00.000000Z"
  "created_at" => "2020-10-31 07:07:00.000000Z"
]

Get URL

Getting the URL with a code.

echo shortURL('3dc0c3deda')->url;     // http://127.0.0.1:8000/97b3b32933

// Blade
@shortURL('3dc0c3deda')               // http://127.0.0.1:8000/97b3b32933

Expriation

Checking if it's an expired URL or not.

shortURL('3dc0c3deda')->expired       // false

Expriation

Checking if it's an expired URL or not.

shortURL('3dc0c3deda')->regenerate()  // Returns ShortURL Object

// RESULT
Pharaonic\Laravel\ShortURL\ShortURL { ▼
  ...
  #original: array:7 [▼
    "code" => "97b3b32933"
    "type" => "url"
    "data" => "{"url":"https:\/\/raggitech.com"}"
    "expire_at" => "2027-07-07 00:00:00"
    "user_id" => null
    "updated_at" => "2020-10-31 07:07:00"
    "created_at" => "2020-10-31 07:07:00"
  ]
  ...
}