Skip to content
This repository has been archived by the owner on Nov 11, 2017. It is now read-only.

Jugglio/UniqueHashids

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.