Skip to content

HashId Implementation on Laravel Eloquent ORM

Notifications You must be signed in to change notification settings

iniandrew/laravel-hashid

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laravel HashId


Automatic HashId generator for your eloquent model.

Install

composer require veelasky/laravel-hashid

With laravel package auto discovery, this will automatically add this package to your laravel application.

Simply add HashableId trait on any of your eloquent model you are intending to use with HashId.

Example:

    use Illuminate\Database\Eloquent\Model;
    use Veelasky\LaravelHashId\Eloquent\HashableId;

    class User extends Model {
        use HashableId;

        ...
    }

Usage

// instance of user
$user = User::find(1);

// generate HashId
$user->hash;

// querying for user with specific hash
$user = User::byHash($hash); // $hash: insert any hash that you want to check.

// querying for user with specific hash and throw EloquentModelNotFound exception
$user = User::byHashOrFail($hash);

// convert id to hash from User static instance;
User::idToHash($id);

// convert hash to id from User static instance;
User::hashToId($hash);

About

HashId Implementation on Laravel Eloquent ORM

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • PHP 100.0%