kduma / eloquent-tokenable
Allows using tokens (HashIDs) instead of id in Laravel Eloquent models.
v3.0.0
2026-04-08 15:01 UTC
Requires
- php: ^8.3
- hashids/hashids: ^4.0 || ^5.0
- illuminate/database: ^13.0
This package is auto-updated.
Last update: 2026-04-08 15:03:30 UTC
README
Eloquent trait for exposing Hashids-based tokens on Laravel models instead of numeric IDs.
Full documentation: opensource.duma.sh/libraries/php/eloquent-tokenable
Requirements
- PHP
^8.3 - Laravel
^13.0
Installation
composer require kduma/eloquent-tokenable
Usage
use KDuma\Eloquent\Tokenable; use KDuma\Eloquent\Attributes\HasToken; #[HasToken(length: 10)] class Order extends Model { use Tokenable; }
$order = Order::find(1); echo $order->token; // e.g. "k3Zx9mPqW2" $order = Order::whereToken('k3Zx9mPqW2')->first();