Download the PHP package sharelov/sharelov-shortener without Composer
On this page you can find all versions of the php package sharelov/sharelov-shortener. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download sharelov/sharelov-shortener
More information about sharelov/sharelov-shortener
Files in sharelov/sharelov-shortener
Package sharelov-shortener
Short Description A configurable tool for shortening urls inside a Laravel project.
License MIT
Informations about the package sharelov-shortener
Sharelov : URL Shortener
develop | master |
---|---|
Installation
Require the package with Composer:
After that, add the ServiceProvider to the providers array in config/app.php
You can optionally use the facade. If you decide to use it, add this to your aliases array in config/app.php
:
Then, run composer dump-autoload
.
Afterwards, run php artisan vendor:publish
to get the migration and config files.
Configuration
The config file has important configuration you may want to look at and customize before running the migrations. If you haven't looked at it yet, you can customize the table name in the config file, so there will be no need to fiddle with the migration yourself. Once you make sure the table name will not cause conflicts with your existing tables, run php artisan migrate
to install the table we use.
There is also the posibility to configure any of the following things:
- Hash length. (Default = 5)
- Maximum attempts at generating a unique hash. (Default = 3)
- Usage of Soft Deletes with your short links model. (Default = false)
There is ample documentation for each option in the config file. Feel free to trim it down after having looked it over and setting it up.
Usage
Use this route to decode a shortened URL, if the URL doesn't exist it will run abort(404)
otherwise it will perform a redirect to the stored url asociated with that hash.
Use this route to shorten a URL, if the URL already exists on the database it will return the hash code otherwise it will create a new URL|Hash tuple and it will return a json response with the hash and the url with the current domain indicating the status of the request.
The url receives the following query parameters:
Url to process by the shortener: url=urltoshorten
Expiration date for the link expires_at=YYYY-MM-DD
(don't specify this in order to make the link not expire)
You can have an example of the requests on this postman collection: PostMan Shortener Collection
Succesfull json response
Unsuccessfull json response
For using the facade don't forget to include it use Shortener;
and then you can call the next methods:
Returns the hash for the url sended as a parameter and stores an object in the links table.
Returns the url corresponding to a hash string in the database.
License
This Laravel package is licensed with the MIT License.