marjose/url-shortener
Composer 安装命令:
composer require marjose/url-shortener
包简介
This will generate a shorten URL based on the supplied URL
README 文档
README
This is where your description should go. Limit it to a paragraph or two. Consider adding a small example.
Installation
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 ];
Usage
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']);
Testing
composer test
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Credits
License
The MIT License (MIT). Please see License File for more information.
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-09-28