2017 © Pedro Peláez
 

library hashids

A Hashids bridge for Laravel

image

lingxi/hashids

A Hashids bridge for Laravel

  • Wednesday, March 7, 2018
  • by RryLee
  • Repository
  • 3 Watchers
  • 17 Stars
  • 1,680 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 1 Open issues
  • 9 Versions
  • 6 % Grown

The README.md

Laravel Hashids

Latest Stable VersionTotal DownloadsLicense, (*1)

安装

composer require lingxi/hashids

添加到 app.php

Lingxi\Hashids\HashidsServiceProvider::class
'Hashids' => Lingxi\Hashids\Facades\Hashids::class

Config

php artisan vendor:publish --provider='Lingxi\Hashids\HashidsServiceProvider'
<?php

return [

    'default' => 'main',

    'middleware' => [
        'open' => true,

        // 路由中需要被 decode 的 id
        'route_parameters' => [
            //
        ],

        // 请求参数需要被 decode 的 id
        'request_parameters' => [
            //
        ]
    ],

    // 开启严格模式之后,解密 id 错误会抛出异常
    'strict' => [
        'enable' => true,
        'default' => 0,
    ],

    'connections' => [

        'main' => [
            'prefix' => '',
            'salt' => 'your-salt-string',
            'length' => 'your-length-integer',
            'alphabet' => 'your-alphabet-string',
        ],

    ],

];

Middleware

添加中间件, (*2)

如果是全局中间件,那么对 route 参数是无法自动 decode 的, (*3)

\Lingxi\Hashids\Middleware\DecodePublicIdMiddleware::class,

在 config/hashids.php 中去配置需要解密的路由参数以及请求参数, (*4)

Model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;
use Lingxi\Hashids\ModelTraits\PublicId;

class Post extends Model
{
    use PublicId;

    public function comments()
    {
        return $this->morphMany(\App\Comment::class, 'commentable');
    }
}

Then, get public id., (*5)

Post::first()->public_id

Debug

php artisan id:en 1 --uri=p

php artisan id:de sdfghjkla;sdjhasjhdfgahjsdjasd

The Versions

07/03 2018

dev-master

9999999-dev

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt bitly hash youtube ids hashids obfuscate hashid

07/03 2018

v0.1.0

0.1.0.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt hashids hashid

07/09 2017

v0.0.7

0.0.7.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt hashids hashid

21/05 2017

v0.0.6

0.0.6.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt hashids hashid

19/05 2017

v0.0.5

0.0.5.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt hashids hashid

07/04 2017

v0.0.4

0.0.4.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt hashids hashid

01/04 2017

v0.0.3

0.0.3.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt bitly hash youtube ids hashids obfuscate hashid

01/04 2017

v0.0.2

0.0.2.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt bitly hash youtube ids hashids obfuscate hashid

19/03 2017

v0.0.1

0.0.1.0

A Hashids bridge for Laravel

  Sources   Download

MIT

The Requires

 

The Development Requires

laravel encrypt decrypt bitly hash youtube ids hashids obfuscate hashid