specs/hashids-laravel

Laravel 的 hashids(hashids)包装器

0.1.2 2016-06-29 10:34 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:53:12 UTC


README

Laravel 的 hashids(hashids)包装器。

Hashids 是一个小的 PHP 类,可以从一个或多个数字生成类似 YouTube 的 ID。在您不想向用户暴露数据库 ID 时使用 hashids。

安装

composer.json 中添加包

"require": {
    "specs/hashids-laravel": "^0.1"
},

config/app.php 中添加 hashids 的服务提供者

'providers' => array(

    Illuminate\Validation\ValidationServiceProvider::class,
    ...
    Illuminate\View\ViewServiceProvider::class,

    Specs\Hashids\HashidsServiceProvider::class,
),

以及 hashids 的外观(同样在 config/app.php 中)

'aliases' => array(

    'App' => Illuminate\Support\Facades\App::class,
    ...
    'View' => Illuminate\Support\Facades\View::class,

    'Hashids' => Specs\Hashids\HashidsFacade::class,

),

您还应该发布配置文件。

php artisan vendor:publish --tag=config

然后重置 config/hashids.php 中的默认值。

示例用法

使用 Hashids 外观

$id = Hashids::encode(1, 2, 3);
$numbers = Hashids::decode($id);

var_dump($id, $numbers);
string(5) "laHquq"
array(3) {
  [0]=>
  int(1)
  [1]=>
  int(2)
  [2]=>
  int(3)
}

更多用法