PHPackages                             olakunlevpn/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. olakunlevpn/token

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

olakunlevpn/token
=================

Unique Token Generator For Laravel

1.0(6y ago)02MITPHPPHP &gt;=5.6

Since Apr 3Pushed 5y ago1 watchersCompare

[ Source](https://github.com/olakunlevpn/laravel-token)[ Packagist](https://packagist.org/packages/olakunlevpn/token)[ RSS](/packages/olakunlevpn-token/feed)WikiDiscussions master Synced today

READMEChangelogDependenciesVersions (2)Used By (0)

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

[](#laravel-token)

[![Laravel](https://camo.githubusercontent.com/97b5803421d3fe4307917cb5ab71bb9ad8ea9b32346d92cf52bf68c697d15478/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f6474666276766b79702f696d6167652f75706c6f61642f76313536363333313337372f6c61726176656c2d6c6f676f6c6f636b75702d636d796b2d7265642e737667)](https://camo.githubusercontent.com/97b5803421d3fe4307917cb5ab71bb9ad8ea9b32346d92cf52bf68c697d15478/68747470733a2f2f7265732e636c6f7564696e6172792e636f6d2f6474666276766b79702f696d6167652f75706c6f61642f76313536363333313337372f6c61726176656c2d6c6f676f6c6f636b75702d636d796b2d7265642e737667)

[![Total Downloads](https://camo.githubusercontent.com/edbfd91d13274721ee569e30d83e249acfb5e7aa49077708b5c8349b15d0487c/68747470733a2f2f696d672e736869656c64732e696f2f7061636b61676973742f64742f6c65616775652f736b656c65746f6e2e7376673f7374796c653d666c61742d737175617265)](https://packagist.org/packages/olakunlevpn/token)

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 olakunlevpn/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.

```
Olakunlevpn\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'=>\Olakunlevpn\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 OlakunlevpnToken;` 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 OlakunlevpnMultiToken;` 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) © [Olakunlevpn](https://github.com/olakunlevpn)

###  Health Score

22

—

LowBetter than 22% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity2

Limited adoption so far

Community7

Small or concentrated contributor base

Maturity51

Maturing project, gaining track record

 Bus Factor1

Top contributor holds 100% 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

Unknown

Total

1

Last Release

2227d ago

### Community

Maintainers

![](https://www.gravatar.com/avatar/1a7e5e8b085ae7575db3d809fe0475fff50fb845de72bf218aa3f38bc0dc1c32?d=identicon)[olakunlevpn](/maintainers/olakunlevpn)

---

Top Contributors

[![olakunlevpn](https://avatars.githubusercontent.com/u/20794807?v=4)](https://github.com/olakunlevpn "olakunlevpn (7 commits)")

---

Tags

laraveltokengeneratePHP tokentoken generatorunique tokenlaravel token

### Embed Badge

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

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

###  Alternatives

[dirape/token

Unique Token Generator For Laravel

28277.4k2](/packages/dirape-token)[okipa/laravel-table

Generate tables from Eloquent models.

56752.8k](/packages/okipa-laravel-table)[shetabit/token-builder

Laravel Token Builder

236.7k](/packages/shetabit-token-builder)[evilfreelancer/openvpn-php

OpenVPN config generator writen on PHP

304.7k](/packages/evilfreelancer-openvpn-php)[kevinsimard/laravel-cookieless-session

Laravel middleware to start a cookieless session

1417.0k](/packages/kevinsimard-laravel-cookieless-session)[okipa/laravel-form-components

Ready-to-use and customizable form components.

198.0k1](/packages/okipa-laravel-form-components)

PHPackages © 2026

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