3

我正在使用vinkla/hashids,我已经按照以下步骤

  1. 作曲家需要vinkla/hashids
  2. 将服务提供者添加到 providers 数组中的 config/app.php
  3. 如果你愿意,你可以使用门面。将 config/app.php 中的引用添加到您的别名数组。
  4. php artisan vendor:publish此步骤不会在配置文件中创建 hashid.php
  5. 使用 Vinkla\Hashids\Facades\Hashids;
  6. 哈希::编码(4815162342);

我得到了找不到 hashids 类的错误

4

3 回答 3

3

似乎提供程序没有启动。

尝试这样做:

php artisan config:clear
php artisan clear-compiled

第一个将清除所有缓存的配置文件,后者将清除服务缓存。

它对我有用,希望它也对你有用。

我在这里找到了解决方案:Laravel 5.2 Service provider not booting

于 2016-11-23T16:52:32.923 回答
0

编码只是这样做

\Hashids::encode($characters)

并解码

\Hashids::decode($characters)
于 2017-02-28T02:42:06.537 回答
0

尝试检查您的$laravelSite/config目录,看看您是否找到一个名为hashids.php...的文件

在您的控制器中;也尝试Hashids像这样手动导入类:

<?php
    namespace App\Http\Controllers;

    use Vinkla\Hashids\Facades\Hashids;

    class SampleClass extends  {

        public function testHashID(){
            $h1 = Hashids::encode(4815162342);
            var_dump($h1);
            $h2 = Hashids::decode('oaobgb-rnar');
            var_dump($h2);             
        }
    }

顺便说一下; 如果您没有hashids.php在您的$laravelSite/config目录中看到;您可以尝试手动创建它。该文件只返回一个配置设置数组...文件的内容如下所示:

    /*
     * This file is part of Laravel Hashids.
     *
     * (c) Vincent Klaiber <hello@vinkla.com>
     *
     * For the full copyright and license information, please view the LICENSE
     * file that was distributed with this source code.
     */

    return [

        /*
        |--------------------------------------------------------------------------
        | Default Connection Name
        |--------------------------------------------------------------------------
        |
        | Here you may specify which of the connections below you wish to use as
        | your default connection for all work. Of course, you may use many
        | connections at once using the manager class.
        |
        */

        'default' => 'main',

        /*
        |--------------------------------------------------------------------------
        | Hashids Connections
        |--------------------------------------------------------------------------
        |
        | Here are each of the connections setup for your application. Example
        | configuration has been included, but you may add as many connections as
        | you would like.
        |
        */

        'connections' => [

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

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

        ],

    ];
于 2016-08-11T15:00:40.553 回答