You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The uuid trait automatically generates uuids for your Eloquent models.
8
+
9
+
-[Usage](#usage)
10
+
-[Primary Key](#primary-key)
11
+
-[Custom Column](#custom-column)
12
+
13
+
## Usage
14
+
15
+
Usage is as simple as adding a uuid column to your database and using the trait on your model.
16
+
17
+
```php
18
+
Schema::table('users', function (Blueprint $table)
19
+
{
20
+
$table->uuid('uuid');
21
+
});
22
+
```
23
+
24
+
```php
25
+
use Laratools\Eloquent\Uuid;
26
+
27
+
class User extends Model
28
+
{
29
+
use Uuid;
30
+
}
31
+
```
32
+
33
+
Now, whenever you save a new model, a uuid will be generated.
34
+
35
+
#### Primary Key
36
+
37
+
Using a uuid as the primary key is as simple as setting auto-increments on your model to false.
38
+
39
+
```php
40
+
use Laratools\Eloquent\Uuid;
41
+
42
+
class User extends Model
43
+
{
44
+
use Uuid;
45
+
46
+
public $incrementing = false;
47
+
}
48
+
```
49
+
50
+
## Custom Column
51
+
52
+
By default the trait will assume a column name of `uuid`, however you can customise this on a per-model basis by defining the `UUID_COLUMN` constant on your model.
0 commit comments