Skip to content

Commit 78be67a

Browse files
committed
Add uuid documentation
1 parent 4ced78e commit 78be67a

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

uuid.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
---
2+
currentMenu: uuid
3+
---
4+
5+
# UUID
6+
7+
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.
53+
54+
```php
55+
class User extends Model
56+
{
57+
use Uuid;
58+
59+
const UUID_COLUMN = 'id';
60+
}
61+
```

0 commit comments

Comments
 (0)