, (*1)
A minimal Laravel package for shortening URLs. Apart for creating short URLs - like bitly - it also supported updating URL redirects and tracking URL clicks., (*2)
Laravel URL Shortener
Install the package. It supports Laravel 5.5 and up (including 7.0 and up)., (*3)
composer require arietimmerman/laravel-url-shortener
php artisan migrate
And start shortening URLs, (*4)
~~~.php
(string)URLShortener::shorten("http://www.example.com");, (*5)
Or
~~~.bash
php artisan url:shorten http://www.example.com
Usage for Laravel < 5.5
Add the service provider in your config/app.php
., (*6)
~~~.php
'providers' => [ /* [..] / \ArieTimmerman\Laravel\URLShortener\ServiceProvider::class / [..] */ ];, (*7)
## Optional
Publish the configuration and the view.
~~~.php
php artisan vendor:publish --provider="ArieTimmerman\Laravel\URLShortener\ServiceProvider"
Optionally, register for URLVisit events in your EventServiceProvider
., (*8)
~~~.php
protected $listen = [
'ArieTimmerman\Laravel\URLShortener\Events\URLVisit' => [
'App\Listener\YourListener',
]
];, (*9)
## Configuration
See `config/urlshortener.php`
## Docker
Build and start the docker container.
docker-compose build
docker-compose up, (*10)
Now shorten an URL like this
docker-compose exec laravel-url-shortener php artisan url:shorten https://www.example.com, (*11)
Check out the redirect
curl -v http://localhost:18123/code
~~~, (*12)