mlopez/url-shortener

v1.0.0 2023-03-25 05:05 UTC

This package is auto-updated.

Last update: 2024-09-25 08:11:35 UTC


README

此包在您的Laravel项目中实现了URL缩短器,使用迁移和两个访问路由。它还附带一个配置文件,以便调整您认为必要的设置。

安装

使用composer安装包。

composer require mlopez/url-shortener

可选地,您可以将配置文件和迁移文件发布。

php artisan vendor:publish --tag=url-shortener-migrations
php artisan vendor:publish --tag=url-shortener-config

在composer安装包后,运行以下命令以运行迁移并注册路由。

php artisan url-shortene:install

测试

public function test_url_shortener()
{
    $this->post(route('links.store'), [
        'long_url' => 'https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers'
    ]);

    $this->assertDatabaseHas(config('urlshortener.table'), [
        'long_url' => 'https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers'
    ]);
}

响应

{
  "id": 16,
  "long_url": "https://stackoverflow.com/questions/417142/what-is-the-maximum-length-of-a-url-in-different-browsers",
  "code": "5TPcKQ",
  "short_url": "https://123url.com/5TPcKQ", 🏹
  "updated_at": "2023-03-25T04:59:32.000000Z",
  "created_at": "2023-03-25T04:59:32.000000Z"
}

致谢

许可证

MIT许可证(MIT)。请参阅许可证文件获取更多信息。