THIS VERSION IS DEPRECATED! PLEASE USE sven/unique-hashids INSTEAD., (*1)
Unique Hashids
![Software License][ico-license], (*2)
This is a simple trait for Laravel models to generate
unique ids for them. It uses vinkla's wonderful
Hashids package and is configurable within
the model itself., (*3)
Installation
You may install this package via composer:, (*4)
$ composer require juggl/unique-hashids
Configuration
This will install both this package and Hashids.
Please see the documentation over there to install & configure the hashids. This package
will use the default Hashids driver., (*5)
Usage
To start generating unique ids for your models, all you need to do is use a trait,
like so:, (*6)
namespace App;
use Juggl\UniqueHashids\GeneratesUnique;
use Illuminate\Database\Eloquent\Model;
class YourModel extends Model
{
use GeneratesUnique;
// The rest of your model
}
By default, this package assumes you have a unique_id column on you database
to store the unique id in. Optionally, you may override this by setting a
static property $uniqueColumn on your model:, (*7)
namespace App;
use Juggl\UniqueHashids\GeneratesUnique;
use Illuminate\Database\Eloquent\Model;
class YourModel extends Model
{
use GeneratesUnique;
public static $uniqueColumn = 'my_column'; // this will assume 'unique_id' by default.
// The rest of your model
}
Credits
This package depends on vinkla's excellent Hashids
package, found here., (*8)
License
juggl\unique-hashids is licenced under the MIT License (MIT). Please see the
license file for more information., (*9)