juggl/unique-hashids

This package is abandoned and no longer maintained. The author suggests using the sven/unique-hashids package instead.

Easily create unique ids for a Laravel model.

1.1.0 2015-12-26 16:25 UTC

This package is not auto-updated.

Last update: 2022-02-01 12:54:10 UTC


README

THIS VERSION IS DEPRECATED! PLEASE USE sven/unique-hashids INSTEAD.

Unique Hashids

Latest Version on Packagist Total Downloads Software License

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.

Installation

You may install this package via composer:

$ 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.

Usage

To start generating unique ids for your models, all you need to do is use a trait, like so:

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:

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.

License

juggl\unique-hashids is licenced under the MIT License (MIT). Please see the license file for more information.