ako/shorturl

0.0.6 2019-01-15 14:33 UTC

This package is auto-updated.

Last update: 2024-09-16 00:37:47 UTC


README

Scrutinizer Code Quality Build Status Code Intelligence Status

简单地在本服务器上启动一个网址缩短器。由于本包的主要目的是本地缩短网址,因此目前只提供了 local 驱动程序,而 bitly 和 google 驱动程序将很快添加。

要求

1- php-7.1

2- Laravel-5.5

安装

通过 composer 安装

composer require ako/shorturl

或者在项目的 composer.json 文件中添加 "ako/shorturl":"^0.0.6"

运行 php artisan vendor:publishshorturl.php 配置文件添加到 config 文件夹。

运行 php artisan migrate 创建 links 表。

用法

您可以通过 Laravel Facades 获取 Shorturl 实例。

// Default driver is local
$url = 'http://www.domain.com/here/is/a/long/url';
$short_url = \Shorturl::shorten($url); // http://www.domain.com/abde

// Expand shortened url
$expanded = \Shorturl::expand('http://www.domain.com/abde') // http://www.domain.com/here/is/a/long/url


// Or you can specify the driver
$short_url = \Shorturl::onDriver('local')->shorten($url); // http://www.domain.com/abde
$short_url = \Shorturl::onDriver('bitly')->shorten($url); // http://bit.ly/shortened

// You can add some custom properties when using local driver for later access on the url
$short_url = \Shorturl::onDriver('local')
                  ->withProperties(['key' => value])
                  ->shorten($url); // http://www.domain.com/abde
                  

每次展开网址时,给定网址的 clicks 计数器都会增加,因此您可以对链接进行一些统计分析。

您可以将 \Ako\Shorturl\Models\Link 模型作为 Eloquent 模型使用,以获取每个网址的 clicks 数量、存储的 properties 或链接上的任何其他信息。