UuidAsPrimaryKey   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 12
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 12
rs 10
c 0
b 0
f 0
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A bootUuidAsPrimaryKey() 0 4 1
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