PHPackages                             tpenaranda/aiditokens - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Database &amp; ORM](/categories/database)
4. /
5. tpenaranda/aiditokens

ActiveLibrary[Database &amp; ORM](/categories/database)

tpenaranda/aiditokens
=====================

Use custom tokens instead of IDs on Laravel models.

v1.1.0(6y ago)0221MITPHPPHP ^7.2CI failing

Since Nov 17Pushed 6y ago1 watchersCompare

[ Source](https://github.com/tpenaranda/aiditokens)[ Packagist](https://packagist.org/packages/tpenaranda/aiditokens)[ Docs](https://github.com/tpenaranda/aiditokens)[ RSS](/packages/tpenaranda-aiditokens/feed)WikiDiscussions master Synced today

READMEChangelogDependencies (3)Versions (3)Used By (1)

Laravel Aiditokens
==================

[](#laravel-aiditokens)

[![Latest Stable Version](https://camo.githubusercontent.com/be3d9fb07cb3720973560fb9da99da49fb5539a6e9e236bb0d87346f0128f5c6/68747470733a2f2f706f7365722e707567782e6f72672f7470656e6172616e64612f61696469746f6b656e732f762f737461626c65)](https://packagist.org/packages/tpenaranda/aiditokens) [![Total Downloads](https://camo.githubusercontent.com/f906f677f247a47c34365f9ca1e26f2e2bf0f4e617f5030a7a538694c5cf9ff4/68747470733a2f2f706f7365722e707567782e6f72672f7470656e6172616e64612f61696469746f6b656e732f646f776e6c6f616473)](https://packagist.org/packages/tpenaranda/aiditokens) [![License](https://camo.githubusercontent.com/9fc36fe1bcb486328f18ee7ad068437c56008a5ba0e8f7f4c3f2aa9150804bbc/68747470733a2f2f706f7365722e707567782e6f72672f7470656e6172616e64612f61696469746f6b656e732f6c6963656e7365)](https://packagist.org/packages/tpenaranda/aiditokens)

A Laravel package to reference Models by using custom string tokens instead of IDs.

Use cases
---------

[](#use-cases)

- You want to hide ID information on your endpoints. `/api/user/32` ends as `/api/user/5cb0b0dddf8ae37a6e8066d4ffd838d91c94bdc7`.
- You need to create temporary references to your models. For instance, a link for resetting a password that will expire in two hours `reset/password/user/3f6e660c376c9fcaeaddeb50b0893d73e772100f`.

Installation
------------

[](#installation)

Install package using [Composer](http://getcomposer.org).

```
$ composer require tpenaranda/aiditokens

```

Run migrations.

```
$ php artisan migrate

```

Usage
-----

[](#usage)

- Include Tokens trait on desired Laravel model.

```
class User extends Model
{
    use TPenaranda\Aiditokens\Traits\Tokens;

```

- Get (create if necessary) a token:

```
>>> $userModel->getToken();
=> "5cb0b0dddf8ae37a6e8066d4ffd838d91c94bdc7"
>>>

>>> $userModel->getToken($expireInHours = 2);
=> "efbbc5efa8e0838f58aa86f2f20a468af8262a43"
>>>

```

- Retrieve a model by token:

```
$user = User::firstByToken('5cb0b0dddf8ae37a6e8066d4ffd838d91c94bdc7');
=> App\User {#3214
     id: 53,
     first_name: "John",
     last_name: "Doe",
     created_at: "2019-11-15 07:22:59",
     updated_at: "2019-11-15 07:23:04",

```

- Custom token generation

```
class User extends Model
{
    use TPenaranda\Aiditokens\Traits\Tokens;

    public function generateToken(): string
    {
        return str_random(); // Your custom logic goes here.
    }

```

Advanced usage
--------------

[](#advanced-usage)

- Bind on RouteServiceProvider for route model explicit binding

```
class RouteServiceProvider extends ServiceProvider
{
    public function boot()
    {
        Route::pattern('userToken', '^.{40}$'); // Watch out this regex if you're using custom tokens.

        Route::bind('userToken', function ($value) {
            return User::firstByToken($value) ?? abort(404);
        });

```

- Route file

```
Route::get('users/{userToken}', 'UserController@get');

```

Happy coding!

###  Health Score

24

—

LowBetter than 31% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity6

Limited adoption so far

Community6

Small or concentrated contributor base

Maturity54

Maturing project, gaining track record

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

###  Release Activity

Cadence

Every ~0 days

Total

2

Last Release

2419d ago

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/12966330?v=4)[Tate Peñaranda](/maintainers/tpenaranda)[@tpenaranda](https://github.com/tpenaranda)

---

Tags

bindingeloquent-modelshashlaraveltokenlaraveltokenmodelaiditoken

###  Code Quality

TestsPHPUnit

### Embed Badge

![Health badge](/badges/tpenaranda-aiditokens/health.svg)

```
[![Health](https://phpackages.com/badges/tpenaranda-aiditokens/health.svg)](https://phpackages.com/packages/tpenaranda-aiditokens)
```

###  Alternatives

[anourvalar/eloquent-serialize

Laravel Query Builder (Eloquent) serialization

11223.5M33](/packages/anourvalar-eloquent-serialize)[jeremykenedy/laravel-roles

A Powerful package for handling roles and permissions in Laravel. Supports Laravel 5.3 up to 13.

1.0k849.6k7](/packages/jeremykenedy-laravel-roles)[statamic-rad-pack/runway

Eloquently manage your database models in Statamic.

135224.7k7](/packages/statamic-rad-pack-runway)[waad/laravel-model-metadata

A robust Laravel package for handling metadata with JSON casting, custom relation names, and advanced querying capabilities.

854.6k](/packages/waad-laravel-model-metadata)[akaunting/laravel-sortable

Sortable behavior package for Laravel

27195.7k](/packages/akaunting-laravel-sortable)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
