PHPackages                             dirape/token - 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. [Utility &amp; Helpers](/categories/utility)
4. /
5. dirape/token

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

dirape/token
============

Unique Token Generator For Laravel

V2.3(6y ago)28277.4k↓16.3%132MITPHPPHP &gt;=5.4.0

Since Aug 20Pushed 1y ago1 watchersCompare

[ Source](https://github.com/mustafakhaleddev/laravel-token)[ Packagist](https://packagist.org/packages/dirape/token)[ RSS](/packages/dirape-token/feed)WikiDiscussions master Synced 1mo ago

READMEChangelog (5)Dependencies (1)Versions (6)Used By (2)

Laravel Token
=============

[](#laravel-token)

[![Laravel](https://camo.githubusercontent.com/4429b0ba7396b7916f9b713a734dd468bf1e3d686a2b6172654839915e644c2a/687474703a2f2f676574667265657475746f7269616c2e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031362f30372f4c61726176656c2d46726f6d2d536372617463682e6a7067)](https://camo.githubusercontent.com/4429b0ba7396b7916f9b713a734dd468bf1e3d686a2b6172654839915e644c2a/687474703a2f2f676574667265657475746f7269616c2e636f6d2f77702d636f6e74656e742f75706c6f6164732f323031362f30372f4c61726176656c2d46726f6d2d536372617463682e6a7067)

Laravel unique Token Generator

```
// Generate unique Token From Database.
$new_token = $token->Unique($table_name, $column_name, $size);
```

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

[](#installation)

Require this package, with [Composer](https://getcomposer.org/), in the root directory of your project.

```
$ composer require dirape/token
```

Add the service provider to `config/app.php` in the `providers` array, or if you're using Laravel 5.5, this can be done via the automatic package discovery.

```
Dirape\Token\TokenServiceProvider::class
```

If you want you can use the [facade](http://laravel.com/docs/facades). Add the reference in `config/app.php` to your aliases array.

```
'Token'=>\Dirape\Token\Facades\Facade::class
```

Documentation
-------------

[](#documentation)

### ★ New Token Trait ★

[](#-new-token-trait-)

##### setup in model

[](#setup-in-model)

To use new trait token you need to do some changes in the model that contain the token column.

##### One Column Token

[](#one-column-token)

##### One token Trait allow you to generate token for one columns in the table

[](#one-token-trait-allow-you-to-generate-token-for-one-columns-in-the--table)

- To use one column token you need to add ` use DirapeToken;` in the model .
- In database we use default column called `dt_token` to replace with your column name add `  protected $DT_Column='column_name';` in the model .
- Token settings are set by default to this value ` ['type' => DT_Unique, 'size' => 40, 'special_chr' => false]` to replace with your custom settings add `   protected $DT_settings=['type'=>DT_Unique,'size'=>60,'special_chr'=>false];` in the model .
- you should know that we use custom constants for our token type

```
  Const DT_Unique = 'Unique';
  Const DT_UniqueNum = 'UniqueNumber';
  Const DT_UniqueStr = 'UniqueString';
  Const DT_Random = 'Random';
  Const DT_RandomNum = 'RandomNumber';
  Const DT_RandomStr = 'RandomString';
```

- after preparing the model to use our trait token in your code you can set the token with your custom column and settings like this

```
           $user=User::first();
           $user->setToken();
           $user->save();
```

- you can use your custom settings in `setToken();` function like this

```
           $user=User::first();
           $user->setToken(DT_UniqueStr,100,false);
           $user->save();
```

- you can set your custom column in the function

```
           $user=User::first();
           $user->setToken(DT_UniqueStr,100,false,'column_name');
           $user->save();
```

- To get model query with token you can use `WithToken()` . `$user=User::WithToken()->get();`
- To get model query with no tokens you can use flag `false` in `WithToken()``$user=User::WithToken(false)->get();`

##### Multi Column Token

[](#multi-column-token)

##### Multi token allow you to generate tokens for multi columns in the same table

[](#multi-token-allow-you-to-generate-tokens-for-multi-columns-in-the-same-table)

- To use multi column token you need to add ` use DirapeMultiToken;` in the model .
- Columns settings are not set by default so you need to make your custom settings in the model

```
  protected $DMT_columns=[
        'unique_id'=>['type'=>DT_Unique,'size'=>60,'special_chr'=>false],
        'unique_uid'=>['type'=>DT_Unique,'size'=>30,'special_chr'=>false],
    ];
```

- you should know that we use custom constants for our token type ```
      Const DT_Unique = 'Unique';
      Const DT_UniqueNum = 'UniqueNumber';
      Const DT_UniqueStr = 'UniqueString';
      Const DT_Random = 'Random';
      Const DT_RandomNum = 'RandomNumber';
      Const DT_RandomStr = 'RandomString';
    ```

    - after preparing the model to use our trait multi token in your code you can set the tokens with only one function

    ```
               $user=User::first();
               $user->setTokens();
               $user->save();
    ```

### ★ The old way ★

[](#-the-old-way-)

#### Generate unique token

[](#generate-unique-token)

With this package you can generate unqiue token not repated in database just by using `unique($table_name,$column_name,$size)` Function `$table_name` is the table name in database , `$column_name` is the column name in the table, `$size` is token size.

#### Generate unique string token

[](#generate-unique-string-token)

generate unique strings token with the same signature of unique token with function `UniqueString($table_name,$column_name,$size)`.

#### Generate unique integer token

[](#generate-unique-integer-token)

generate unique integers token with the same signature of unique token with function `UniqueNumber($table_name,$column_name,$size)`.

#### Generate random token

[](#generate-random-token)

generate random token with function `Random($size)` and `$size` is the size of token length.

#### Generate random integer token

[](#generate-random-integer-token)

generate random integer token with function `RandomNumber($size)` and `$size` is the size of token length.

#### Generate random string token

[](#generate-random-string-token)

generate random string token with function `RandomString($size)` and `$size` is the size of token length.

#### Special Characters

[](#special-characters)

use `true` to allow special characters in your token `!@#$%^&*()` in all functions just like `Random($size,true)`.

### Examples

[](#examples)

Here you can see an example of just how simple this package is to use.

#### Unique Token

[](#unique-token)

```
// Generate unique token not rebeated in database table with column name
Token::Unique($table_name, $column_name, 10 );
//Result: fCWih6TDAf

// Generate unique integer token not rebeated in database table with column name
Token::UniqueNumber($table_name, $column_name, 10 );
//Result: 9647307239

// Generate unique string token not rebeated in database table with column name
Token::UniqueString($table_name, $column_name, 10 );
//Result: SOUjkyAyxC

//You can use special characters just add "true" to the function
Token::Unique($table_name, $column_name, 10,true );
//Result: H@klU$u^3z
```

#### Random Token (not unique)

[](#random-token-not-unique)

```
$size=10;
// Generate random token
Token::Random($size);

// Generate random integer token
Token::RandomNumber($size);

// Generate random string token
Token::RandomString($size);

//You can use special characters just add "true" to the function
Token::Random($size,true);
```

License
-------

[](#license)

[MIT](LICENSE) © [Mustafa Khaled](https://github.com/mustafakhaleddev)

###  Health Score

42

—

FairBetter than 90% of packages

Maintenance26

Infrequent updates — may be unmaintained

Popularity46

Moderate usage in the ecosystem

Community18

Small or concentrated contributor base

Maturity62

Established project with proven stability

 Bus Factor1

Top contributor holds 68.8% of commits — single point of failure

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 ~242 days

Total

5

Last Release

2226d ago

Major Versions

v1.0 → v2.02018-05-10

### Community

Maintainers

![](https://avatars.githubusercontent.com/u/25182746?v=4)[Mustafa Khaled](/maintainers/mustafakhaleddev)[@mustafakhaleddev](https://github.com/mustafakhaleddev)

---

Top Contributors

[![mustafakhaleddev](https://avatars.githubusercontent.com/u/25182746?v=4)](https://github.com/mustafakhaleddev "mustafakhaleddev (22 commits)")[![markwalet](https://avatars.githubusercontent.com/u/11446771?v=4)](https://github.com/markwalet "markwalet (9 commits)")[![DariusIII](https://avatars.githubusercontent.com/u/3399658?v=4)](https://github.com/DariusIII "DariusIII (1 commits)")

---

Tags

laraveltokengeneratePHP tokentoken generatorunique tokenlaravel token

### Embed Badge

![Health badge](/badges/dirape-token/health.svg)

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

###  Alternatives

[barryvdh/laravel-ide-helper

Laravel IDE Helper, generates correct PHPDocs for all Facade classes, to improve auto-completion.

14.9k123.0M687](/packages/barryvdh-laravel-ide-helper)[shetabit/token-builder

Laravel Token Builder

236.7k](/packages/shetabit-token-builder)[interaction-design-foundation/laravel-geoip

Support for multiple Geographical Location services.

17221.0k3](/packages/interaction-design-foundation-laravel-geoip)[nedwors/navigator

A Laravel package to ease defining navigation menus

433.1k](/packages/nedwors-navigator)[kevinsimard/laravel-cookieless-session

Laravel middleware to start a cookieless session

1417.0k](/packages/kevinsimard-laravel-cookieless-session)

PHPackages © 2026

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