veelasky / laravel-hashid by veelasky

HashId Implementation on Laravel Eloquent ORM
60,066
40
1
Package Data
Maintainer Username: veelasky
Maintainer Contact: veelasky@pm.com (Rifki Alhuraibi)
Package Create Date: 2018-01-22
Package Last Update: 2024-03-22
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-03-27 03:15:34
Package Statistics
Total Downloads: 60,066
Monthly Downloads: 5,350
Daily Downloads: 240
Total Stars: 40
Total Watchers: 1
Total Forks: 17
Total Open Issues: 2

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