Download the PHP package cedaesca/urlshortener without Composer
On this page you can find all versions of the php package cedaesca/urlshortener. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download cedaesca/urlshortener
More information about cedaesca/urlshortener
Files in cedaesca/urlshortener
Package urlshortener
Short Description Shorten URL's using your own domain
License MIT
Informations about the package urlshortener
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
Installing
1) Download it into your Laravel app using composer
2) Publish the packages files `
3) Run the migrations. `
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: ``
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:
``
Redirecting users
First off, the redirection route expect a shortlink
parameter, make sure to name it like that. Later, you can redirect the user to the expected target by returning Laravel's redirect response and giving the returning value of the target
method as an argument. The target
method also receives the \Illuminate\Http\Request
instance.
Logging redirected clients
You may want to track some statistics with your shortened URL's. At the moment you can track their user agent, their IP Address and the timestamps. You can decide what to do with that info.
To achieve this, call the log method before the target one in your redirect response. Give the `\Illuminate\Http\Request
as the argument and now you can leave the target
argument blank.
``
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 default_redirect
value for that of your preference.