marjose/url-shortener

这将根据提供的URL生成一个缩短的URL

v1.0.0 2021-09-28 07:04 UTC

This package is auto-updated.

Last update: 2024-08-29 05:44:22 UTC


README

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

这里应该放置您的描述。限制为一到两段。考虑添加一个小示例。

安装

您可以通过Composer安装此包

composer require marjose/UrlShortener

您可以使用以下命令发布和运行迁移

php artisan vendor:publish --provider="Marjose\UrlShortener\UrlShortenerServiceProvider" --tag="UrlShortener-migrations"
php artisan migrate

您可以使用以下命令发布配置文件

php artisan vendor:publish --provider="Marjose\UrlShortener\UrlShortenerServiceProvider" --tag="UrlShortener-config"

这是发布配置文件的内容

return [
    'length' => 6, // Length of the string for shortening the URL
    'expiration' => 120, // minutes, 0 for no expiration
];

使用方法

使用配置文件中的默认设置生成URL

use Marjose\UrlShortener\Facades\UrlShortener;
$response = UrlShortener::url('https://xxxx.xx/xxxx')->generate();

通过添加过期时间到链接来生成URL

use Marjose\UrlShortener\Facades\UrlShortener;
$response = UrlShortener::url('https://xxxx.xx/xxxx')->setExpiration(15)->generate();

通过覆盖配置文件中的默认设置来生成URL

use Marjose\UrlShortener\Facades\UrlShortener;
$response = UrlShortener::url('https://xxxx.xx/xxxx')->setLength(5)->setExpiration(15)->generate();

验证缩短的URL是否已过期

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

在您的web.php路由中,您可以添加一个类似的新路由,以便在您的控制器验证链接后捕获并重定向到原始链接。

Route::get('s/{url_key}',[YourControllerHere::class, 'YourControllerMethod']);

测试

composer test

变更日志

有关最近更改的更多信息,请参阅变更日志

贡献

有关详细信息,请参阅贡献指南

鸣谢

许可

MIT许可(MIT)。有关更多信息,请参阅许可文件