@@ 15-34 (lines=20) @@ | ||
12 | ||
13 | use Ramsey\Uuid\Uuid; |
|
14 | ||
15 | trait UuidForPrimary |
|
16 | { |
|
17 | ||
18 | /** |
|
19 | * Boot the Uuid trait for the model. |
|
20 | * |
|
21 | * @return void |
|
22 | */ |
|
23 | public static function bootUuidForPrimary() |
|
24 | { |
|
25 | static::creating(function ($model) { |
|
26 | $key = $model->getKeyName(); |
|
27 | if (empty($model->attributes[$key])) { |
|
28 | $model->incrementing = false; |
|
29 | $model->{$key} = Uuid::uuid4()->toString(); |
|
30 | } |
|
31 | }); |
|
32 | } |
|
33 | ||
34 | } |
|
35 |
@@ 15-34 (lines=20) @@ | ||
12 | ||
13 | use Ramsey\Uuid\Uuid; |
|
14 | ||
15 | trait UuidForKey |
|
16 | { |
|
17 | ||
18 | /** |
|
19 | * Boot the Uuid trait for the model. |
|
20 | * |
|
21 | * @return void |
|
22 | */ |
|
23 | public static function bootUuidForKey() |
|
24 | { |
|
25 | static::creating(function ($model) { |
|
26 | $key = $model->getKeyName(); |
|
27 | if (empty($model->attributes[$key])) { |
|
28 | $model->incrementing = false; |
|
29 | $model->{$key} = Uuid::uuid1()->toString(); |
|
30 | } |
|
31 | }); |
|
32 | } |
|
33 | ||
34 | } |
|
35 |