Skip to content

Commit 43cffb0

Browse files
committed
Update readme
1 parent 3c637a0 commit 43cffb0

File tree

1 file changed

+116
-88
lines changed

1 file changed

+116
-88
lines changed

README.md

Lines changed: 116 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
Laravel unique Token Generator
66
```php
77
// Generate unique Token From Database.
8-
$new_token = $token->unique($table_name, $column_name, $size);
8+
$new_token = $token->Unique($table_name, $column_name, $size);
9+
910
```
1011

1112
## Installation
@@ -25,131 +26,158 @@ Dirape\Token\TokenServiceProvider::class
2526
If you want you can use the [facade](http://laravel.com/docs/facades). Add the reference in `config/app.php` to your aliases array.
2627

2728
```php
28-
'Token' => \Dirape\Token\Facades\Facade::class
29+
'Token'=>\Dirape\Token\Facades\Facade::class
2930
```
3031

31-
## Usage
32+
## Documentation
3233

33-
If you want to use a token in you model, you have to add the `DirapeToken` or `DirapeMultiToken` trait to your Eloquent model, depending on if you want to use multiple tokens per model.
34-
To use trait token you need to do some changes in the model that contain the token column.
34+
### ★ New Token Trait ★
35+
##### setup in model
36+
To use new trait token you need to do some changes in the model that contain the token column.
37+
##### One Column Token
3538

36-
### Single token
39+
##### One token Trait allow you to generate token for one columns in the table
3740

38-
* The token gets stored in the database. The column is called `dt_token` by default. To change this, you can add a `protected $DT_column` property to your model.
39-
* 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.
41+
* To use one column token you need to add `` use DirapeToken;`` in the model .
42+
* In database we use default column called ``dt_token`` to replace with your column name add `` protected $DT_Column='column_name';`` in the model .
43+
* 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 .
4044
* you should know that we use custom constants for our token type
4145
```php
42-
const DT_Unique = 'Unique';
43-
const DT_UniqueNum = 'UniqueNumber';
44-
const DT_UniqueStr = 'UniqueString';
45-
const DT_Random = 'Random';
46-
const DT_RandomNum = 'RandomNumber';
47-
const DT_RandomStr = 'RandomString';
48-
```
46+
Const DT_Unique = 'Unique';
47+
Const DT_UniqueNum = 'UniqueNumber';
48+
Const DT_UniqueStr = 'UniqueString';
49+
Const DT_Random = 'Random';
50+
Const DT_RandomNum = 'RandomNumber';
51+
Const DT_RandomStr = 'RandomString';
52+
```
4953
* 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
5054
```php
51-
$user = User::first();
52-
$user->setToken();
53-
$user->save();
55+
$user=User::first();
56+
$user->setToken();
57+
$user->save();
5458
```
55-
* you can use your custom settings in `setToken();` function like this
59+
* you can use your custom settings in ``setToken();`` function like this
5660
```php
57-
$user = User::first();
58-
$user->setToken(DT_UniqueStr, 100, false);
59-
$user->save();
61+
$user=User::first();
62+
$user->setToken(DT_UniqueStr,100,false);
63+
$user->save();
6064
```
6165
* you can set your custom column in the function
6266
```php
63-
$user = User::first();
64-
$user->setToken(DT_UniqueStr, 100, false, 'column_name');
65-
$user->save();
67+
$user=User::first();
68+
$user->setToken(DT_UniqueStr,100,false,'column_name');
69+
$user->save();
6670
```
6771
* To get model query with token you can use `WithToken()` .
68-
```
69-
$user = User::withToken()->get();
70-
```
72+
```
73+
$user=User::WithToken()->get();
74+
```
7175
* To get model query with no tokens you can use flag ``false`` in `WithToken()`
72-
```
73-
$user = User::withToken(false)->get();
74-
```
75-
### Multiple tokens
76+
```
77+
$user=User::WithToken(false)->get();
78+
```
79+
##### Multi Column Token
80+
81+
##### Multi token allow you to generate tokens for multi columns in the same table
7682

83+
* To use multi column token you need to add `` use DirapeMultiToken;`` in the model .
7784
* Columns settings are not set by default so you need to make your custom settings in the model
7885
```php
79-
protected $DMT_columns = [
80-
'unique_id' => [
81-
'type' => DT_Unique,
82-
'size' => 60,
83-
'special_chr' => false
84-
],
85-
'unique_uid' => [
86-
'type' => DT_Unique,
87-
'size' => 30,
88-
'special_chr' => false
89-
],
90-
];
86+
protected $DMT_columns=[
87+
'unique_id'=>['type'=>DT_Unique,'size'=>60,'special_chr'=>false],
88+
'unique_uid'=>['type'=>DT_Unique,'size'=>30,'special_chr'=>false],
89+
];
90+
9191
```
9292
* you should know that we use custom constants for our token type
93-
```php
94-
const DT_Unique = 'Unique';
95-
const DT_UniqueNum = 'UniqueNumber';
96-
const DT_UniqueStr = 'UniqueString';
97-
const DT_Random = 'Random';
98-
const DT_RandomNum = 'RandomNumber';
99-
const DT_RandomStr = 'RandomString';
100-
```
93+
```php
94+
Const DT_Unique = 'Unique';
95+
Const DT_UniqueNum = 'UniqueNumber';
96+
Const DT_UniqueStr = 'UniqueString';
97+
Const DT_Random = 'Random';
98+
Const DT_RandomNum = 'RandomNumber';
99+
Const DT_RandomStr = 'RandomString';
100+
```
101101
* after preparing the model to use our trait multi token in your code you can set the tokens with only one function
102-
```php
103-
$user = User::first();
104-
$user->setTokens();
105-
$user->save();
106-
```
107-
## Methods
102+
```php
103+
$user=User::first();
104+
$user->setTokens();
105+
$user->save();
106+
```
107+
108+
109+
### ★ The old way ★
110+
#### Generate unique token
108111

109-
Here you can see an example of just how simple this package is to use.
112+
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.
110113

111-
### Random tokens
112114

113-
```php
114-
// Generate random token with upper- and lowercase letter and numbers. (a-z, A-Z, 0-9)
115-
Token::random('users', 'api_token', 60);
116-
// Results in: "6nz1pk70YdQZP01tPXdQArx6B6IVwr7v3vnKqLYkamAifvmrG8TVrza42wZt"
115+
#### Generate unique string token
117116

118-
// Generate random token with numbers. (0-9)
119-
Token::randomNumber('products', 'identifier', 15);
120-
// Results in: "964730723939485"
117+
generate unique strings token with the same signature of unique token with function `UniqueString($table_name,$column_name,$size)`.
121118

122-
// Generate random token with upper- and lowercase letters. (a-z, A-Z)
123-
Token::randomString('coupons', 'code', 10);
124-
// Results in: "bIQBqnlRzG"
125-
```
126119

127-
### Unique tokens
120+
#### Generate unique integer token
121+
122+
generate unique integers token with the same signature of unique token with function `UniqueNumber($table_name,$column_name,$size)`.
123+
124+
125+
#### Generate random token
126+
generate random token with function `Random($size)` and `$size` is the size of token length.
127+
128+
129+
#### Generate random integer token
130+
generate random integer token with function `RandomNumber($size)` and `$size` is the size of token length.
131+
132+
133+
#### Generate random string token
134+
generate random string token with function `RandomString($size)` and `$size` is the size of token length.
135+
136+
#### Special Characters
137+
138+
use `true` to allow special characters in your token `!@#$%^&*()` in all functions just like `Random($size,true)`.
139+
140+
### Examples
141+
142+
Here you can see an example of just how simple this package is to use.
143+
#### Unique Token
128144
```php
129-
// Generate unique token with upper- and lowercase letter and numbers. (a-z, A-Z, 0-9)
130-
Token::unique('users', 'api_token', 60);
131-
// Results in: "6nz1pk70YdQZP01tPXdQArx6B6IVwr7v3vnKqLYkamAifvmrG8TVrza42wZt"
132145

133-
// Generate unique token with numbers. (0-9)
134-
Token::uniqueNumber('products', 'identifier', 15);
135-
// Results in: "964730723939485"
146+
// Generate unique token not rebeated in database table with column name
147+
Token::Unique($table_name, $column_name, 10 );
148+
//Result: fCWih6TDAf
149+
150+
151+
// Generate unique integer token not rebeated in database table with column name
152+
Token::UniqueNumber($table_name, $column_name, 10 );
153+
//Result: 9647307239
136154

137-
// Generate unique token with upper- and lowercase letters. (a-z, A-Z)
138-
Token::uniqueString('coupons', 'code', 10);
139-
// Results in: "bIQBqnlRzG"
140-
```
141155

142-
### Special characters
156+
// Generate unique string token not rebeated in database table with column name
157+
Token::UniqueString($table_name, $column_name, 10 );
158+
//Result: SOUjkyAyxC
143159

144-
For every method there is an optional last parameter. This parameter determines if the token can contain special characters. (`!@#$%^&*()`)
145160

161+
//You can use special characters just add "true" to the function
162+
Token::Unique($table_name, $column_name, 10,true );
163+
//Result: H@klU$u^3z
164+
```
165+
166+
#### Random Token (not unique)
146167
```php
168+
$size=10;
169+
// Generate random token
170+
Token::Random($size);
171+
172+
// Generate random integer token
173+
Token::RandomNumber($size);
174+
175+
// Generate random string token
176+
Token::RandomString($size);
147177

148-
Token::unique('users', 'api_token', 60, true);
149-
// Results in "^QRMBksyp*(tGfLlzp9JCFayE7!gIpb1ssjrIyECp9$S2wM1VeL7fzARm!sU"
178+
//You can use special characters just add "true" to the function
179+
Token::Random($size,true);
150180

151-
Token::randomString(15, true);
152-
// Results in "$YnBG(jFSbpL^EF"
153181
```
154182

155183
## License

0 commit comments

Comments
 (0)