我正在使用vinkla / hashids,我已按照以下步骤进行操作
我得到没有找到哈希类的错误
答案 0 :(得分:3)
似乎提供商没有启动。
尝试这样做:
php artisan config:clear
php artisan clear-compiled
第一个将清除所有缓存的配置文件,后者将清除服务缓存。
它对我有用,希望它也适合你。
我在这里找到了解决方案:Laravel 5.2 Service provider not booting
答案 1 :(得分: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',
],
],
];
答案 2 :(得分:0)
要编码,只需执行此操作
\Hashids::encode($characters)
并解码
\Hashids::decode($characters)