Local link shortener for Laravel 7
You can install the package via composer:
composer require danielebuso/shortener
Publish the migration and migrate
php artisan vendor:publish --tag=migrations
php artisan migrate
$short_link = Shortener::shorten('https://example.com/my-very-long-link');
$short_link->short_url // Eg. https://myapp.com/l/JedO8TSC
To customize the link routing add the following to your routes and customize as you wish
Route::domain('mylink.com')->group(function () {
Route::get('{short_link}', 'ShortLinkController@resolve')->name('short_link');
});
// Then in controller
$short_link->short_url // Eg. https://mylink.com/JedO8TSC
To customize the config either use the environment variables or publish the configuration file
php artisan vendor:publish --tag=config
Config | .env | Default | Description |
---|---|---|---|
link_length | SHORTENER_LINK_LENGTH | 8 | Number of random characters used in link generation |
composer test
- Custom validity (nbf, exp)
- Link analitycs (times opened)
- Real tests
If you discover any security related issues, please email [email protected] instead of using the issue tracker.
The MIT License (MIT). Please see License File for more information.