UuidAsPrimaryKey::bootUuidAsPrimaryKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace Thinkstudeo\Rakshak\Traits;
4
5
use Illuminate\Support\Str;
6
7
trait UuidAsPrimaryKey
8
{
9
    /**
10
     * Generate a uuid and insert it as primary key for the model being created.
11
     * Set the $incrementing to false to use the uuid primary key.
12
     *
13
     * @return void
14
     */
15
    public static function bootUuidAsPrimaryKey(): void
16
    {
17
        static::creating(function ($model) {
18
            $model->{$model->getKeyName()} = Str::orderedUuid()->toString();
19
        });
20
    }
21
}
22