3
votes

I am using vinkla/hashids and i have followed the following steps

  1. composer require vinkla/hashids
  2. Add the service provider to config/app.php in the providers array
  3. If you want you can use the facade. Add the reference in config/app.php to your aliases array.
  4. php artisan vendor:publish this step does not create hashid.php in config file
  5. use Vinkla\Hashids\Facades\Hashids;
  6. Hashids::encode(4815162342);

And i get error that hashids class not found

3
Did you alias Vinkla\Hashids\Facades\Hashids in config/app.php or not?Jared Eitnier
yes i mentioned it in step 3Awais Mushtaq
Have you tried composer dump-autoload at all? Might help if you show the controller or library class that is trying to generate a hashid.Jared Eitnier
yes i have tried everything . composer update, composer install and dump auto-loadAwais Mushtaq
Just for Test purposes, try manually importing the classes by adding explicit require_once __DIR__ . $pathToVinklaHashidsClass;. From your observation after that; you may debug/troubleshoot from there.Poiz

3 Answers

3
votes

It seems that the provider is not booting.

Try to do this:

php artisan config:clear
php artisan clear-compiled

The first will clear any cached config files, and the later will clear the services cache.

It worked for me, hope it works for you too.

I found the solution here: Laravel 5.2 Service provider not booting

0
votes

Try checking inside your $laravelSite/config Directory to see if you find a file called hashids.php...

In your Controller; try also to import the the Hashids Class manually like so:

<?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);             
        }
    }

And by the way; if you don't see hashids.php within your $laravelSite/config Directory; you may try to manually create it. The file just returns an array of Configuration Settings... the content to the file looks like so:

    /*
     * This file is part of Laravel Hashids.
     *
     * (c) Vincent Klaiber <[email protected]>
     *
     * 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
votes

To encode just do this

\Hashids::encode($characters)

And to decode

\Hashids::decode($characters)