{"id":21880918,"url":"https://github.com/mustafakhaleddev/laravel-token","last_synced_at":"2025-08-21T05:32:03.961Z","repository":{"id":56969411,"uuid":"100867296","full_name":"mustafakhaleddev/laravel-token","owner":"mustafakhaleddev","description":"Generate unique Laravel Token","archived":false,"fork":false,"pushed_at":"2024-06-02T10:55:54.000Z","size":24,"stargazers_count":28,"open_issues_count":0,"forks_count":13,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-01T13:46:42.376Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mustafakhaleddev.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-20T14:34:11.000Z","updated_at":"2025-03-05T14:15:41.000Z","dependencies_parsed_at":"2024-06-18T15:29:35.906Z","dependency_job_id":null,"html_url":"https://github.com/mustafakhaleddev/laravel-token","commit_stats":{"total_commits":23,"total_committers":3,"mean_commits":7.666666666666667,"dds":0.3913043478260869,"last_synced_commit":"653590e561641e94f04c40e3034c6cd3436cda7d"},"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/mustafakhaleddev/laravel-token","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustafakhaleddev%2Flaravel-token","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustafakhaleddev%2Flaravel-token/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustafakhaleddev%2Flaravel-token/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustafakhaleddev%2Flaravel-token/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mustafakhaleddev","download_url":"https://codeload.github.com/mustafakhaleddev/laravel-token/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mustafakhaleddev%2Flaravel-token/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":271430764,"owners_count":24758366,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-08-21T02:00:08.990Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-28T09:16:57.708Z","updated_at":"2025-08-21T05:32:03.664Z","avatar_url":"https://github.com/mustafakhaleddev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel Token\r\n\r\n![Laravel](http://getfreetutorial.com/wp-content/uploads/2016/07/Laravel-From-Scratch.jpg)\r\n\r\nLaravel unique Token Generator \r\n```php\r\n// Generate unique Token From Database.\r\n$new_token = $token-\u003eUnique($table_name, $column_name, $size);\r\n\r\n```\r\n\r\n## Installation\r\n\r\nRequire this package, with [Composer](https://getcomposer.org/), in the root directory of your project.\r\n\r\n```bash\r\n$ composer require dirape/token\r\n```\r\n\r\nAdd 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.\r\n\r\n```php\r\nDirape\\Token\\TokenServiceProvider::class\r\n```\r\n\r\nIf you want you can use the [facade](http://laravel.com/docs/facades). Add the reference in `config/app.php` to your aliases array.\r\n\r\n```php\r\n'Token'=\u003e\\Dirape\\Token\\Facades\\Facade::class\r\n```\r\n\r\n## Documentation\r\n\r\n### ★ New Token Trait ★\r\n##### setup in model\r\nTo use new trait token you need to do some changes in the model that contain the token column.\r\n##### One Column Token\r\n\r\n##### One token Trait allow you to generate token for one columns in the  table\r\n\r\n* To use one column token you need to add `` use DirapeToken;`` in the model .\r\n* In database we use default column called ``dt_token`` to replace with your column name add  ``  protected $DT_Column='column_name';`` in the model .\r\n* Token settings are set by default to this value `` ['type' =\u003e DT_Unique, 'size' =\u003e 40, 'special_chr' =\u003e false]`` to replace with your custom settings add  ``    protected $DT_settings=['type'=\u003eDT_Unique,'size'=\u003e60,'special_chr'=\u003efalse]; `` in the model .\r\n* you should know that we use custom constants for our token type\r\n```php\r\n  Const DT_Unique = 'Unique'; \r\n  Const DT_UniqueNum = 'UniqueNumber'; \r\n  Const DT_UniqueStr = 'UniqueString';\r\n  Const DT_Random = 'Random';\r\n  Const DT_RandomNum = 'RandomNumber';\r\n  Const DT_RandomStr = 'RandomString';\r\n  ``` \r\n * 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\r\n```php\r\n           $user=User::first();\r\n           $user-\u003esetToken();\r\n           $user-\u003esave();\r\n```\r\n* you can use your custom settings in ``setToken();`` function like this\r\n```php\r\n           $user=User::first();\r\n           $user-\u003esetToken(DT_UniqueStr,100,false);\r\n           $user-\u003esave();\r\n```\r\n* you can set your custom column in the function\r\n ```php\r\n            $user=User::first();\r\n            $user-\u003esetToken(DT_UniqueStr,100,false,'column_name');\r\n            $user-\u003esave();\r\n ```      \r\n* To get model query with token you can use `WithToken()` .\r\n       ```\r\n                  $user=User::WithToken()-\u003eget();\r\n       ```\r\n* To get model query with no tokens you can use flag ``false``  in `WithToken()`\r\n       ```\r\n                       $user=User::WithToken(false)-\u003eget();\r\n            ```\r\n##### Multi Column Token\r\n\r\n##### Multi token allow you to generate tokens for multi columns in the same table\r\n  \r\n  * To use multi column token you need to add `` use DirapeMultiToken;`` in the model .\r\n  * Columns settings are not set by default so you need to make your custom settings in the model\r\n```php\r\n  protected $DMT_columns=[\r\n        'unique_id'=\u003e['type'=\u003eDT_Unique,'size'=\u003e60,'special_chr'=\u003efalse],\r\n        'unique_uid'=\u003e['type'=\u003eDT_Unique,'size'=\u003e30,'special_chr'=\u003efalse],\r\n    ];\r\n\r\n``` \r\n* you should know that we use custom constants for our token type\r\n  ```php\r\n    Const DT_Unique = 'Unique'; \r\n    Const DT_UniqueNum = 'UniqueNumber'; \r\n    Const DT_UniqueStr = 'UniqueString';\r\n    Const DT_Random = 'Random';\r\n    Const DT_RandomNum = 'RandomNumber';\r\n    Const DT_RandomStr = 'RandomString';\r\n    ``` \r\n   * after preparing the model to use our trait multi token in your code you can set the tokens with only one function\r\n  ```php\r\n             $user=User::first();\r\n             $user-\u003esetTokens();\r\n             $user-\u003esave();\r\n  ```\r\n    \r\n          \r\n### ★ The old way ★\r\n#### Generate unique token\r\n\r\nWith 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.\r\n\r\n\r\n#### Generate unique string token\r\n\r\ngenerate unique strings token with the same signature  of unique token with function `UniqueString($table_name,$column_name,$size)`.\r\n\r\n\r\n#### Generate unique integer token\r\n\r\ngenerate unique integers token with the same signature  of unique token with function `UniqueNumber($table_name,$column_name,$size)`.\r\n\r\n\r\n#### Generate random token\r\ngenerate random token with function `Random($size)` and `$size` is the size of token length.\r\n\r\n\r\n#### Generate random integer token\r\ngenerate random integer token with function `RandomNumber($size)` and `$size` is the size of token length.\r\n\r\n\r\n#### Generate random string token\r\ngenerate random string token with function `RandomString($size)` and `$size` is the size of token length.\r\n\r\n#### Special Characters\r\n\r\nuse `true` to allow special characters in your token `!@#$%^\u0026*()` in all functions just like `Random($size,true)`.\r\n\r\n### Examples\r\n\r\nHere you can see an example of just how simple this package is to use.\r\n#### Unique Token\r\n```php\r\n\r\n// Generate unique token not rebeated in database table with column name \r\nToken::Unique($table_name, $column_name, 10 );\r\n//Result: fCWih6TDAf\r\n\r\n\r\n// Generate unique integer token not rebeated in database table with column name\r\nToken::UniqueNumber($table_name, $column_name, 10 );\r\n//Result: 9647307239\r\n\r\n\r\n// Generate unique string token not rebeated in database table with column name\r\nToken::UniqueString($table_name, $column_name, 10 );\r\n//Result: SOUjkyAyxC\r\n\r\n\r\n//You can use special characters just add \"true\" to the function\r\nToken::Unique($table_name, $column_name, 10,true );\r\n//Result: H@klU$u^3z\r\n```\r\n\r\n#### Random Token (not unique)\r\n```php\r\n$size=10;\r\n// Generate random token \r\nToken::Random($size);\r\n\r\n// Generate random integer token\r\nToken::RandomNumber($size);\r\n\r\n// Generate random string token\r\nToken::RandomString($size);\r\n\r\n//You can use special characters just add \"true\" to the function\r\nToken::Random($size,true);\r\n\r\n```\r\n\r\n## License\r\n\r\n[MIT](LICENSE) © [Mustafa Khaled](https://github.com/mustafakhaleddev)\r\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustafakhaleddev%2Flaravel-token","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmustafakhaleddev%2Flaravel-token","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmustafakhaleddev%2Flaravel-token/lists"}