teertz/shortlink

通过ID生成短链接

v1.0.1 2016-10-12 16:33 UTC

This package is not auto-updated.

Last update: 2024-09-28 20:20:01 UTC


README

简介

Teertz Shortlink 通过传递对象ID以简单的方式生成短链接路径,并将其存储在您数据库中,以满足您的需求。

生成的链接类似于: http://example.com/abdg;

基本用法

要开始使用 Teertz Shortlink,将其添加到您的 composer.json 文件中作为依赖项

composer require teertz/shortlink

获取完整路径

<?php

use Teertz\Shortlink\Generator as Shortlink;

class SomeClass
{
    public function saveObject($id)
    {
        /* some work before */

        $shortlink = (new Shortlink('http://example.com'))->get(1);
        // output 'http://example.com/aaaa';

        $shortlink = (new Shortlink('http://example.com'))->get(4);
        // output 'http://example.com/aaad';

        /* some work after */
    

    }
}

使用 Laravel 进行配置

Shortlink 面板添加到您的 app 配置文件中的 aliases 数组

'Shortlink' => Teertz\Shortlink\Generator::class,

许可证

Teertz Shortlink 是开源软件,许可协议为 MIT 许可证