cedaesca/urlshortener

Shorten URL's using your own domain

v0.1.13 2019-06-06 05:37 UTC

README

License: MIT

URL Shortener

Shorten URL's using your own domain

Getting Started

These instructions will get you a copy of the project up and running on your local machine for development and testing purposes. See deployment for notes on how to deploy the project on a live system.

Prerequisites

Laravel 5.8+ (Not tested in previous versions)

Installing

  1. Download it into your Laravel app using composer
composer require cedaesca/urlshortener
  1. Publish the packages files
php artisan vendor:publish
  1. Run the migrations.
php artisan migrate

Customizing the URL's code length

  1. Go to the config file located on config/cedaesca/URLShortener.php

  2. Change the length value for that of your preference.

URLShortener Facade

You have to add the URLShortener facade to your controller:

use cedaesca\URLShortener\Facades\URLShortener;

Then you'll have access to the create and redirect methods.

Shorten URL's

Use the create static method to shorten a given URL. This method receives the request as argument and returns an instance of the model if was successfully created or false if not:

URLShortener::create(Request $request);

Redirecting users

Use the redirectstatic method to redirect users to the target url's. This method receives the URL code parameter as argument.

Route::get('/r/{code}', 'UrlShortenerController@redirect')->name('rthis');
return URLShortener::redirect($code);

Default redirect

If the code given as argument is invalid, the redirect method will redirect the user to a default route. Change this from the config file.

  1. Go to the config file located on config/cedaesca/URLShortener.php

  2. Change the defaultRedirect value for that of your preference.