Skip to content

Commit

Permalink
add genuid
Browse files Browse the repository at this point in the history
  • Loading branch information
yaza-putu committed Nov 27, 2021
1 parent 946bc11 commit e4266f0
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Traits/GenUid.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace LaravelEasyRepository\Mutators;


trait GenUid
{
/**
* Boot function from Laravel.
*/
protected static function boot()
{
parent::boot();
static::creating(function ($model) {
if (empty($model->{$model->getKeyName()})) {
$model->{$model->getKeyName()} = uid();
}
});
}

/**
* Get the value indicating whether the IDs are incrementing.
*
* @return bool
*/
public function getIncrementing()
{
return false;
}

/**
* Get the auto-incrementing key type.
*
* @return string
*/
public function getKeyType()
{
return 'string';
}
}

0 comments on commit e4266f0

Please sign in to comment.