Skip to content

Commit ee02819

Browse files
Added how generating IDs works in the docs
1 parent 550f605 commit ee02819

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,24 @@ class User extends Authenticatable
8888
}
8989
```
9090

91+
### Generating UUIDs
92+
93+
If you don't specify the value for the primary key of your model, a UUIDv4 will
94+
be automatically generated. However, if you do specify your own UUIDv4 then it
95+
will not generate one, but instead use the one you have explicity provided. This
96+
can be useful when needing the know the ID of the model before you have created
97+
it:
98+
99+
```php
100+
// No UUID provided (automatically generated).
101+
$model = Model::create();
102+
echo $model->id; // abb034ae-fcdc-4200-8094-582b60a4281f
103+
104+
// UUID explicity provided.
105+
$model = Model::create(['id' => '04d7f995-ef33-4870-a214-4e21c51ff76e']);
106+
echo $model->id; // 04d7f995-ef33-4870-a214-4e21c51ff76e
107+
```
108+
91109
## Running the tests
92110

93111
To run the test suite you can use the following commands:

0 commit comments

Comments
 (0)