This will generate a shorten URL based on the supplied URL
marjose/url-shortener is a Laravel package for this will generate a shorten url based on the supplied url.
It currently has 0 GitHub stars and 3 downloads on Packagist (latest version v1.0.0).
Install it with composer require marjose/url-shortener.
Discover more Laravel packages by marjose
or browse all Laravel packages to compare alternatives.
Last updated
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
You can install the package via composer:
composer require marjose/UrlShortener
You can publish and run the migrations with:
php artisan vendor:publish --provider="Marjose\UrlShortener\UrlShortenerServiceProvider" --tag="UrlShortener-migrations"
php artisan migrate
You can publish the config file with:
php artisan vendor:publish --provider="Marjose\UrlShortener\UrlShortenerServiceProvider" --tag="UrlShortener-config"
This is the contents of the published config file:
return [
'length' => 6, // Length of the string for shortening the URL
'expiration' => 120, // minutes, 0 for no expiration
];
Generating the URL by using the default setting from the Config file.
use Marjose\UrlShortener\Facades\UrlShortener;
$response = UrlShortener::url('https://xxxx.xx/xxxx')->generate();
Generating the URL by adding expiration to the link.
use Marjose\UrlShortener\Facades\UrlShortener;
$response = UrlShortener::url('https://xxxx.xx/xxxx')->setExpiration(15)->generate();
Generating the URL by overriding the default setting from the Config file.
use Marjose\UrlShortener\Facades\UrlShortener;
$response = UrlShortener::url('https://xxxx.xx/xxxx')->setLength(5)->setExpiration(15)->generate();
Validate if the shorted URL is expired or not
use Marjose\UrlShortener\Facades\UrlShortener;
$response = UrlShortener::url('https://xxxx.xx/xxxx')->isExpired();
// This will return boolean or an exception if the supplied url is not found in the database
In your web.php route you can add a new route similar to this, so that you can capture and redirect to the original link once the like is validated by your controller.
Route::get('s/{url_key}',[YourControllerHere::class, 'YourControllerMethod']);
composer test
Please see CHANGELOG for more information on what has changed recently.
Please see CONTRIBUTING for details.
The MIT License (MIT). Please see License File for more information.