首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在Laravel 5.2中使用vinkla/hashids软件包

在Laravel 5.2中使用vinkla/hashids软件包
EN

Stack Overflow用户
提问于 2016-08-11 13:41:45
回答 3查看 2.6K关注 0票数 4

我正在使用vinkla/hashids,我遵循了以下步骤

  1. 作曲家要求文可拉/哈希德
  2. 将服务提供程序添加到providers数组中的config/app.php
  3. 如果你愿意的话你可以用门面。将config/app.php中的引用添加到别名数组中。
  4. publish供应商:发布本步骤不在配置文件中创建hashid.php
  5. 使用Vinkla\Hashids\Facades\Hashids;
  6. 哈希::编码(4815162342);

我得到的错误是没有找到hashids类

EN

回答 3

Stack Overflow用户

发布于 2016-11-23 16:52:32

似乎提供程序没有启动。

试着这样做:

代码语言:javascript
复制
php artisan config:clear
php artisan clear-compiled

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

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

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

票数 3
EN

Stack Overflow用户

发布于 2016-08-11 15:00:40

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

在Controller中,也尝试手动导入Hashids类,如下所示:

代码语言:javascript
复制
<?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,您可以尝试手动创建它。该文件只返回一个配置设置数组.文件的内容如下所示:

代码语言:javascript
复制
    /*
     * 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',
            ],

        ],

    ];
票数 0
EN

Stack Overflow用户

发布于 2017-02-28 02:42:06

要编码,只需这样做

代码语言:javascript
复制
\Hashids::encode($characters)

和解码

代码语言:javascript
复制
\Hashids::decode($characters)
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/38898075

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档